diff options
Diffstat (limited to 'app/models/ci')
-rw-r--r-- | app/models/ci/build_trace_chunk.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/models/ci/build_trace_chunk.rb b/app/models/ci/build_trace_chunk.rb index 4856f10846c..4884e355c36 100644 --- a/app/models/ci/build_trace_chunk.rb +++ b/app/models/ci/build_trace_chunk.rb @@ -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 ## |