debian-mirror-gitlab/app/services/ci/queue/build_queue_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
1.6 KiB
Ruby
Raw Normal View History

2021-09-30 23:02:18 +05:30
# frozen_string_literal: true
module Ci
module Queue
class BuildQueueService
include ::Gitlab::Utils::StrongMemoize
attr_reader :runner
def initialize(runner)
@runner = runner
end
def new_builds
strategy.new_builds
end
##
# This is overridden in EE
#
def builds_for_shared_runner
strategy.builds_for_shared_runner
end
# rubocop:disable CodeReuse/ActiveRecord
def builds_for_group_runner
2022-08-13 15:12:31 +05:30
strategy.builds_for_group_runner
2021-09-30 23:02:18 +05:30
end
def builds_for_project_runner
relation = new_builds
2021-11-11 11:23:49 +05:30
.where(project: runner_projects_relation)
2021-09-30 23:02:18 +05:30
order(relation)
end
def builds_queued_before(relation, time)
relation.queued_before(time)
end
def builds_for_protected_runner(relation)
relation.ref_protected
end
def builds_matching_tag_ids(relation, ids)
strategy.builds_matching_tag_ids(relation, ids)
end
def builds_with_any_tags(relation)
strategy.builds_with_any_tags(relation)
end
def order(relation)
strategy.order(relation)
end
def execute(relation)
strategy.build_ids(relation)
end
private
def strategy
strong_memoize(:strategy) do
2022-08-13 15:12:31 +05:30
Queue::PendingBuildsStrategy.new(runner)
2021-09-30 23:02:18 +05:30
end
end
2021-11-11 11:23:49 +05:30
def runner_projects_relation
2022-01-26 12:08:38 +05:30
runner
.runner_projects
.select('"ci_runner_projects"."project_id"::bigint')
2021-11-11 11:23:49 +05:30
end
2021-09-30 23:02:18 +05:30
end
end
end
Ci::Queue::BuildQueueService.prepend_mod_with('Ci::Queue::BuildQueueService')