diff options
author | Felipe Artur <felipefac@gmail.com> | 2017-12-11 19:00:11 -0200 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-12-13 12:15:04 -0200 |
commit | 7ccb283da490a6f2cacaf06bbe6b3f7ae155d870 (patch) | |
tree | 2e7b28fee9133b2cf2f936207367153e75009025 /app/workers | |
parent | 0cdc840b7fd710e58130a06e94d508c7c8cb133b (diff) | |
download | gitlab-ce-issue_41021.tar.gz |
Prevent worker that updates merge requests head pipeline from failing jobsissue_41021
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/stuck_merge_jobs_worker.rb | 8 | ||||
-rw-r--r-- | app/workers/update_head_pipeline_for_merge_request_worker.rb | 13 |
2 files changed, 19 insertions, 2 deletions
diff --git a/app/workers/stuck_merge_jobs_worker.rb b/app/workers/stuck_merge_jobs_worker.rb index 36d2a2e6466..e31fa0fea47 100644 --- a/app/workers/stuck_merge_jobs_worker.rb +++ b/app/workers/stuck_merge_jobs_worker.rb @@ -23,7 +23,13 @@ class StuckMergeJobsWorker merge_requests = MergeRequest.where(id: completed_ids) merge_requests.where.not(merge_commit_sha: nil).update_all(state: :merged) - merge_requests.where(merge_commit_sha: nil).update_all(state: :opened, merge_jid: nil) + + merge_requests_to_reopen = merge_requests.where(merge_commit_sha: nil) + merge_requests_to_reopen.update_all(merge_jid: nil) + + # Do not reopen merge requests using direct queries. + # We rely on state machine callbacks to update head_pipeline_id + merge_requests_to_reopen.map(&:unlock_mr) Rails.logger.info("Updated state of locked merge jobs. JIDs: #{completed_jids.join(', ')}") end diff --git a/app/workers/update_head_pipeline_for_merge_request_worker.rb b/app/workers/update_head_pipeline_for_merge_request_worker.rb index 0a2e9b63578..9614daf1976 100644 --- a/app/workers/update_head_pipeline_for_merge_request_worker.rb +++ b/app/workers/update_head_pipeline_for_merge_request_worker.rb @@ -8,8 +8,19 @@ class UpdateHeadPipelineForMergeRequestWorker pipeline = Ci::Pipeline.where(project: merge_request.source_project, ref: merge_request.source_branch).last return unless pipeline && pipeline.latest? - raise ArgumentError, 'merge request sha does not equal pipeline sha' if merge_request.diff_head_sha != pipeline.sha + + if merge_request.diff_head_sha != pipeline.sha + log_error_message_for(merge_request) + + return + end merge_request.update_attribute(:head_pipeline_id, pipeline.id) end + + def log_error_message_for(merge_request) + Gitlab::EnvironmentLogger.error( + "Outdated head pipeline for active merge request: id=#{merge_request.id}, source_branch=#{merge_request.source_branch}, diff_head_sha=#{merge_request.diff_head_sha}" + ) + end end |