Clean up worker
This commit is contained in:
parent
ded38d5f48
commit
3b569fceff
3 changed files with 38 additions and 26 deletions
|
@ -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
|
||||
|
||||
##
|
||||
|
|
23
app/workers/ci/rescue_stale_live_trace_worker.rb
Normal file
23
app/workers/ci/rescue_stale_live_trace_worker.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
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
|
|
@ -1,26 +0,0 @@
|
|||
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
|
Loading…
Reference in a new issue