Extract updating pipeline status to async worker
This commit is contained in:
parent
578638742a
commit
7d4767fb48
3 changed files with 24 additions and 13 deletions
|
@ -78,10 +78,14 @@ class CommitStatus < ActiveRecord::Base
|
|||
end
|
||||
|
||||
after_transition do |commit_status, transition|
|
||||
if commit_status.pipeline && !transition.loopback?
|
||||
ProcessPipelineWorker.perform_async(
|
||||
commit_status.pipeline.id, process: commit_status.complete?
|
||||
)
|
||||
return if transition.loopback?
|
||||
|
||||
commit_status.pipeline.try(:id).try do |pipeline_id|
|
||||
if commit_status.complete?
|
||||
ProcessPipelineWorker.perform_async(pipeline_id)
|
||||
end
|
||||
|
||||
UpdatePipelineWorker.perform_async(pipeline_id)
|
||||
end
|
||||
|
||||
true
|
||||
|
|
|
@ -3,15 +3,10 @@ class ProcessPipelineWorker
|
|||
|
||||
sidekiq_options queue: :default
|
||||
|
||||
def perform(pipeline_id, params)
|
||||
begin
|
||||
pipeline = Ci::Pipeline.find(pipeline_id)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
return
|
||||
end
|
||||
def perform(pipeline_id)
|
||||
pipeline = Ci::Pipeline.find_by(id: pipeline_id)
|
||||
return unless pipeline
|
||||
|
||||
pipeline.process! if params['process']
|
||||
|
||||
pipeline.update_status
|
||||
pipeline.process!
|
||||
end
|
||||
end
|
||||
|
|
12
app/workers/update_pipeline_worker.rb
Normal file
12
app/workers/update_pipeline_worker.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
class UpdatePipelineWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: :default
|
||||
|
||||
def perform(pipeline_id)
|
||||
pipeline = Ci::Pipeline.find_by(id: pipeline_id)
|
||||
return unless pipeline
|
||||
|
||||
pipeline.update_status
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue