diff options
-rw-r--r-- | app/workers/concerns/pipeline_queue.rb | 12 | ||||
-rw-r--r-- | app/workers/pipeline_update_worker.rb | 2 | ||||
-rw-r--r-- | spec/workers/concerns/pipeline_queue_spec.rb | 14 |
3 files changed, 25 insertions, 3 deletions
diff --git a/app/workers/concerns/pipeline_queue.rb b/app/workers/concerns/pipeline_queue.rb index ca3860e1d38..ed882e3ecef 100644 --- a/app/workers/concerns/pipeline_queue.rb +++ b/app/workers/concerns/pipeline_queue.rb @@ -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 diff --git a/app/workers/pipeline_update_worker.rb b/app/workers/pipeline_update_worker.rb index 96c4152c674..086d00b7ec8 100644 --- a/app/workers/pipeline_update_worker.rb +++ b/app/workers/pipeline_update_worker.rb @@ -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) diff --git a/spec/workers/concerns/pipeline_queue_spec.rb b/spec/workers/concerns/pipeline_queue_spec.rb index 40794d0e42a..3049f2b2ab4 100644 --- a/spec/workers/concerns/pipeline_queue_spec.rb +++ b/spec/workers/concerns/pipeline_queue_spec.rb @@ -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 |