Module: API::Ci::Helpers::RunnerJobExecutionStatusHelper

Included in:
Entities::Ci::Runner, Entities::Ci::RunnerManager
Defined in:
lib/api/ci/helpers/runner_job_execution_status_helper.rb

Instance Method Summary collapse

Instance Method Details

#lazy_job_execution_status(object:, key:) ⇒ Object

Efficiently determines job execution status for multiple runners using BatchLoader to avoid N+1 queries. Returns :active if runner has executing builds, :idle otherwise.



9
10
11
12
13
14
15
16
17
# File 'lib/api/ci/helpers/runner_job_execution_status_helper.rb', line 9

def lazy_job_execution_status(object:, key:)
  BatchLoader.for(object.id).batch(key: key) do |object_ids, loader|
    statuses = object.class.id_in(object_ids).with_executing_builds.index_by(&:id)

    object_ids.each do |id|
      loader.call(id, statuses[id] ? :active : :idle)
    end
  end
end