diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-05-22 22:50:35 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-06-06 17:49:48 +0900 |
commit | c33cedd0f5dba9e501df386b8ead376e29cc7e5d (patch) | |
tree | ff05a39ed91367091c98913114b3b9bc11717d29 /app/workers | |
parent | d10fbde40e48816962ec1ba6acd39e1350216cc5 (diff) | |
download | gitlab-ce-c33cedd0f5dba9e501df386b8ead376e29cc7e5d.tar.gz |
Use each_batch to find rows efficiently with group_by
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/rescue_stale_live_trace_worker.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/app/workers/rescue_stale_live_trace_worker.rb b/app/workers/rescue_stale_live_trace_worker.rb index 42c4364789e..4e2db8de31e 100644 --- a/app/workers/rescue_stale_live_trace_worker.rb +++ b/app/workers/rescue_stale_live_trace_worker.rb @@ -6,20 +6,21 @@ class RescueStaleLiveTraceWorker # Reschedule to archive live traces # # The target jobs are with the following conditions - # - Finished 1 day ago, but it has not had an acthived trace yet - # Jobs finished 1 day ago should have an archived trace. Probably ArchiveTraceWorker failed by Sidekiq's inconsistancy + # - Finished 1 hour ago, but it has not had an acthived trace yet + # Jobs finished 1 hour ago should have an archived trace. Probably ArchiveTraceWorker failed by Sidekiq's inconsistancy Ci::BuildTraceChunk + .include(EachBatch) .select(:build_id) .group(:build_id) .joins(:build) .merge(Ci::Build.finished) .where('ci_builds.finished_at < ?', 1.hour.ago) - .each do |chunks| # TODO: find_each gives an error because of group_by + .each_batch(column: :build_id) do |chunks| build_ids = chunks.map { |chunk| [chunk.build_id] } ArchiveTraceWorker.bulk_perform_async(build_ids) - Rails.logger.warning "Scheduled to archive stale live traces from #{build_ids.min} to #{build_ids.max}" + Rails.logger.info "Scheduled to archive stale live traces from #{build_ids.min} to #{build_ids.max}" end end end |