Extend pipelines queue mixin and add a default queue

This commit is contained in:
Grzegorz Bizon 2017-08-21 13:05:01 +02:00
parent 6509833cfa
commit 0f01ce3657
3 changed files with 25 additions and 3 deletions

View File

@ -1,8 +1,18 @@
##
# Concern for setting Sidekiq settings for the various CI pipeline workers.
#
module PipelineQueue
extend ActiveSupport::Concern
included do
sidekiq_options queue: :pipeline
sidekiq_options queue: 'pipelines-default'
end
class_methods do
def enqueue_in(queue:, group:)
raise ArgumentError if queue.empty? || group.empty?
sidekiq_options queue: "pipelines-#{queue}-#{group}"
end
end
end

View File

@ -2,6 +2,8 @@ class PipelineUpdateWorker
include Sidekiq::Worker
include PipelineQueue
enqueue_in queue: :pipeline, group: :processing
def perform(pipeline_id)
Ci::Pipeline.find_by(id: pipeline_id)
.try(:update_status)

View File

@ -8,7 +8,17 @@ describe PipelineQueue do
end
end
it 'sets the queue name of a worker' do
expect(worker.sidekiq_options['queue'].to_s).to eq('pipeline')
it 'sets a default pipelines queue automatically' do
expect(worker.sidekiq_options['queue'])
.to eq 'pipelines-default'
end
describe '.enqueue_in' do
it 'sets a custom sidekiq queue with prefix, name and group' do
worker.enqueue_in(queue: :build, group: :processing)
expect(worker.sidekiq_options['queue'])
.to eq 'pipelines-build-processing'
end
end
end