diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-10-08 20:25:16 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-10-08 20:25:16 +0200 |
commit | 74fd5cab155cb83ef47ba8f4e78ccfd714f73211 (patch) | |
tree | b179b707ade168a599f13ffb3c0e799330f99b20 | |
parent | 04afdb613e2282fc6a2debb301a32dad08427f8a (diff) | |
download | gitlab-ce-74fd5cab155cb83ef47ba8f4e78ccfd714f73211.tar.gz |
Improve transitions and run hooks after transaction
-rw-r--r-- | app/models/commit_status.rb | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 38554e7a0ca..81f041cf29e 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -85,33 +85,35 @@ class CommitStatus < ActiveRecord::Base commit_status.update_attributes finished_at: Time.now end + 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 + end + end + after_transition [:created, :pending, :running] => :success do |commit_status| - MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.pipeline.project, nil).trigger(commit_status) + commit_status.run_after_commit do + MergeRequests::MergeWhenBuildSucceedsService + .new(pipeline.project, nil).trigger(self) + end end after_transition any => :failed do |commit_status| - MergeRequests::AddTodoWhenBuildFailsService.new(commit_status.pipeline.project, nil).execute(commit_status) + commit_status.run_after_commit do + MergeRequests::AddTodoWhenBuildFailsService + .new(pipeline.project, nil).execute(self) + end end - - after_transition do: :schedule_pipeline_update end delegate :sha, :short_sha, to: :pipeline - def schedule_pipeline_update - run_after_commit(:process_pipeline!) - end - - def process_pipeline! - pipeline.try do |pipeline| - if complete? - ProcessPipelineWorker.perform_async(pipeline.id) - else - UpdatePipelineWorker.perform_async(pipeline.id) - end - end - end - def before_sha pipeline.before_sha || Gitlab::Git::BLANK_SHA end |