diff options
Diffstat (limited to 'app/services/merge_requests/post_merge_service.rb')
-rw-r--r-- | app/services/merge_requests/post_merge_service.rb | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/app/services/merge_requests/post_merge_service.rb b/app/services/merge_requests/post_merge_service.rb index 0364c0dd479..a3d7f623546 100644 --- a/app/services/merge_requests/post_merge_service.rb +++ b/app/services/merge_requests/post_merge_service.rb @@ -8,17 +8,28 @@ module MergeRequests # class PostMergeService < MergeRequests::BaseService def execute(merge_request) - merge_request.mark_as_merged - close_issues(merge_request) - todo_service.merge_merge_request(merge_request, current_user) - create_event(merge_request) - create_note(merge_request) + # These operations need to happen transactionally + ActiveRecord::Base.transaction(requires_new: true) do + merge_request.mark_as_merged + + # These options do not call external services and should be + # relatively quick enough to put in a Transaction + create_event(merge_request) + todo_service.merge_merge_request(merge_request, current_user) + end + + # These operations are idempotent so can be safely run multiple times notification_service.merge_mr(merge_request, current_user) - execute_hooks(merge_request, 'merge') + create_note(merge_request) + close_issues(merge_request) invalidate_cache_counts(merge_request, users: merge_request.assignees) merge_request.update_project_counter_caches delete_non_latest_diffs(merge_request) cleanup_environments(merge_request) + + # Anything after this point will be executed at-most-once. Less important activity only + # TODO: make all the work in here a separate sidekiq job so it can go in the transaction + execute_hooks(merge_request, 'merge') end private |