diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-08-22 14:21:05 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-08-22 14:21:05 +0000 |
commit | 4e4f8534fd5154c35c182379a31201c3a5fe9c20 (patch) | |
tree | 8d264aed73be16c2932a8e3cb7df938934cbf974 /app | |
parent | dc5d755812908455b23f2c9afbec2dab24a3e5ad (diff) | |
parent | d78f0724d9cc3dd7c1f22cef54ad59f8d2b579c4 (diff) | |
download | gitlab-ce-4e4f8534fd5154c35c182379a31201c3a5fe9c20.tar.gz |
Merge branch 'avoid-race-condition-of-archive-trace-cron-worker' into 'master'
Avoid conflicts between ArchiveTracesCronWorker and ArchiveTraceWorker
See merge request gitlab-org/gitlab-ce!31376
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/build.rb | 2 | ||||
-rw-r--r-- | app/workers/ci/archive_traces_cron_worker.rb | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 3c0efca31db..7930bef5cf2 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -121,6 +121,8 @@ module Ci scope :scheduled_actions, ->() { where(when: :delayed, status: COMPLETED_STATUSES + %i[scheduled]) } scope :ref_protected, -> { where(protected: true) } scope :with_live_trace, -> { where('EXISTS (?)', Ci::BuildTraceChunk.where('ci_builds.id = ci_build_trace_chunks.build_id').select(1)) } + scope :with_stale_live_trace, -> { with_live_trace.finished_before(12.hours.ago) } + scope :finished_before, -> (date) { finished.where('finished_at < ?', date) } scope :matches_tag_ids, -> (tag_ids) do matcher = ::ActsAsTaggableOn::Tagging diff --git a/app/workers/ci/archive_traces_cron_worker.rb b/app/workers/ci/archive_traces_cron_worker.rb index 75e68d0233a..ef2da729705 100644 --- a/app/workers/ci/archive_traces_cron_worker.rb +++ b/app/workers/ci/archive_traces_cron_worker.rb @@ -10,7 +10,7 @@ module Ci # Archive stale live traces which still resides in redis or database # This could happen when ArchiveTraceWorker sidekiq jobs were lost by receiving SIGKILL # More details in https://gitlab.com/gitlab-org/gitlab-ce/issues/36791 - Ci::Build.finished.with_live_trace.find_each(batch_size: 100) do |build| + Ci::Build.with_stale_live_trace.find_each(batch_size: 100) do |build| Ci::ArchiveTraceService.new.execute(build, worker_name: self.class.name) end end |