Commit 0f01ce36 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extend pipelines queue mixin and add a default queue

parent 6509833c
##
# Concern for setting Sidekiq settings for the various CI pipeline workers. # Concern for setting Sidekiq settings for the various CI pipeline workers.
#
module PipelineQueue module PipelineQueue
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do 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
end end
...@@ -2,6 +2,8 @@ class PipelineUpdateWorker ...@@ -2,6 +2,8 @@ class PipelineUpdateWorker
include Sidekiq::Worker include Sidekiq::Worker
include PipelineQueue include PipelineQueue
enqueue_in queue: :pipeline, group: :processing
def perform(pipeline_id) def perform(pipeline_id)
Ci::Pipeline.find_by(id: pipeline_id) Ci::Pipeline.find_by(id: pipeline_id)
.try(:update_status) .try(:update_status)
......
...@@ -8,7 +8,17 @@ describe PipelineQueue do ...@@ -8,7 +8,17 @@ describe PipelineQueue do
end end
end end
it 'sets the queue name of a worker' do it 'sets a default pipelines queue automatically' do
expect(worker.sidekiq_options['queue'].to_s).to eq('pipeline') 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
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment