Commit c33cedd0 authored by Shinya Maeda's avatar Shinya Maeda

Use each_batch to find rows efficiently with group_by

parent d10fbde4
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment