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