Commit 47e6f1d6 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor builds queue builder to avoid mutations

parent e9368df2
...@@ -105,28 +105,30 @@ module Ci ...@@ -105,28 +105,30 @@ module Ci
def each_build(params, &blk) def each_build(params, &blk)
queue = ::Gitlab::Ci::Queue::Builder.new(runner) queue = ::Gitlab::Ci::Queue::Builder.new(runner)
if runner.instance_type? builds = begin
queue.builds_for_shared_runner if runner.instance_type?
elsif runner.group_type? queue.builds_for_shared_runner
queue.builds_for_group_runner elsif runner.group_type?
else queue.builds_for_group_runner
queue.builds_for_project_runner else
queue.builds_for_project_runner
end
end end
# pick builds that does not have other tags than runner's one # pick builds that does not have other tags than runner's one
queue.builds_matching_tag_ids(runner.tags.ids) builds = queue.builds_matching_tag_ids(builds, runner.tags.ids)
# pick builds that have at least one tag # pick builds that have at least one tag
unless runner.run_untagged? unless runner.run_untagged?
queue.builds_with_any_tags builds = queue.builds_with_any_tags(builds)
end end
# pick builds that older than specified age # pick builds that older than specified age
if params.key?(:job_age) if params.key?(:job_age)
queue.builds_queued_before(params[:job_age].seconds.ago) builds = queue.builds_queued_before(builds, params[:job_age].seconds.ago)
end end
build_ids = retrieve_queue(-> { queue.build_ids }) build_ids = retrieve_queue(-> { queue.build_ids(builds) })
@metrics.observe_queue_size(-> { build_ids.size }, @runner.runner_type) @metrics.observe_queue_size(-> { build_ids.size }, @runner.runner_type)
......
This diff is collapsed.
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