Extend pipelines queue mixin and add a default queue
This commit is contained in:
parent
6509833cfa
commit
0f01ce3657
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue