Commit 3b569fce authored by Shinya Maeda's avatar Shinya Maeda

Clean up worker

parent ded38d5f
......@@ -50,6 +50,21 @@ module Ci
def finalize_fast_destroy(keys)
redis_delete_data(keys)
end
# Find stale live traces and return their build ids
def find_stale(finished_before: 1.hour.ago)
include(EachBatch)
.select(:build_id)
.group(:build_id)
.joins(:build)
.merge(Ci::Build.finished)
.where('ci_builds.finished_at < ?', finished_before)
.each_batch(column: :build_id) do |chunks|
build_ids = chunks.map { |chunk| [chunk.build_id] }
yield build_ids
end
end
end
##
......
module Ci
class RescueStaleLiveTraceWorker
include ApplicationWorker
include CronjobQueue
def perform
# Reschedule to archive live traces
#
# The targets are jobs with the following conditions
# - It had been finished 1 hour ago, but it has not had an acthived trace yet
# This case happens when sidekiq-jobs of archiving traces are lost in order to restart sidekiq instace which hit RSS limit
Ci::BuildTraceChunk.find_stale(finished_before: 1.hour.ago) do |build_ids|
Ci::Build.where(id: build_ids).find_each do |build|
begin
build.trace.archive!
rescue => e
Rails.logger.info "Failed to archive stale live trace. id: #{build.id} message: #{e.message}"
end
end
end
end
end
end
class RescueStaleLiveTraceWorker
include ApplicationWorker
include CronjobQueue
def perform
# Reschedule to archive live traces
#
# The targets are jobs with the following conditions
# - It had been finished 1 hour ago, but it has not had an acthived trace yet
# This case happens when sidekiq-jobs of archiving traces are lost in order to restart sidekiq instace which hit RSS limit
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_batch(column: :build_id) do |chunks|
build_ids = chunks.map { |chunk| [chunk.build_id] }
ArchiveTraceWorker.bulk_perform_async(build_ids)
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