Commit 74fd5cab authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve transitions and run hooks after transaction

parent 04afdb61
......@@ -85,33 +85,35 @@ class CommitStatus < ActiveRecord::Base
commit_status.update_attributes finished_at: Time.now
end
after_transition [:created, :pending, :running] => :success do |commit_status|
MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.pipeline.project, nil).trigger(commit_status)
after_transition do |commit_status|
commit_status.run_after_commit do
pipeline.try do |pipeline|
if complete?
ProcessPipelineWorker.perform_async(pipeline.id)
else
UpdatePipelineWorker.perform_async(pipeline.id)
end
end
after_transition any => :failed do |commit_status|
MergeRequests::AddTodoWhenBuildFailsService.new(commit_status.pipeline.project, nil).execute(commit_status)
end
after_transition do: :schedule_pipeline_update
end
delegate :sha, :short_sha, to: :pipeline
def schedule_pipeline_update
run_after_commit(:process_pipeline!)
after_transition [:created, :pending, :running] => :success do |commit_status|
commit_status.run_after_commit do
MergeRequests::MergeWhenBuildSucceedsService
.new(pipeline.project, nil).trigger(self)
end
end
def process_pipeline!
pipeline.try do |pipeline|
if complete?
ProcessPipelineWorker.perform_async(pipeline.id)
else
UpdatePipelineWorker.perform_async(pipeline.id)
after_transition any => :failed do |commit_status|
commit_status.run_after_commit do
MergeRequests::AddTodoWhenBuildFailsService
.new(pipeline.project, nil).execute(self)
end
end
end
delegate :sha, :short_sha, to: :pipeline
def before_sha
pipeline.before_sha || Gitlab::Git::BLANK_SHA
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