Class: Ci::Queue::BuildQueueService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/ci/queue/build_queue_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(runner) ⇒ BuildQueueService

Returns a new instance of BuildQueueService.


10
11
12
# File 'app/services/ci/queue/build_queue_service.rb', line 10

def initialize(runner)
  @runner = runner
end

Instance Attribute Details

#runnerObject (readonly)

Returns the value of attribute runner.


8
9
10
# File 'app/services/ci/queue/build_queue_service.rb', line 8

def runner
  @runner
end

Instance Method Details

#builds_for_group_runnerObject

rubocop:disable CodeReuse/ActiveRecord


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/ci/queue/build_queue_service.rb', line 26

def builds_for_group_runner
  if strategy.use_denormalized_data_strategy?
    strategy.builds_for_group_runner
  else
    # Workaround for weird Rails bug, that makes `runner.groups.to_sql` to return `runner_id = NULL`
    groups = ::Group.joins(:runner_namespaces).merge(runner.runner_namespaces)

    hierarchy_groups = Gitlab::ObjectHierarchy
      .new(groups)
      .base_and_descendants

    projects = Project.where(namespace_id: hierarchy_groups)
      .with_group_runners_enabled
      .with_builds_enabled
      .without_deleted

    relation = new_builds.where(project: projects)

    order(relation)
  end
end

#builds_for_project_runnerObject


48
49
50
51
52
53
# File 'app/services/ci/queue/build_queue_service.rb', line 48

def builds_for_project_runner
  relation = new_builds
    .where(project: runner_projects_relation)

  order(relation)
end

#builds_for_protected_runner(relation) ⇒ Object


59
60
61
# File 'app/services/ci/queue/build_queue_service.rb', line 59

def builds_for_protected_runner(relation)
  relation.ref_protected
end

#builds_for_shared_runnerObject

This is overridden in EE


21
22
23
# File 'app/services/ci/queue/build_queue_service.rb', line 21

def builds_for_shared_runner
  strategy.builds_for_shared_runner
end

#builds_matching_tag_ids(relation, ids) ⇒ Object


63
64
65
# File 'app/services/ci/queue/build_queue_service.rb', line 63

def builds_matching_tag_ids(relation, ids)
  strategy.builds_matching_tag_ids(relation, ids)
end

#builds_queued_before(relation, time) ⇒ Object


55
56
57
# File 'app/services/ci/queue/build_queue_service.rb', line 55

def builds_queued_before(relation, time)
  relation.queued_before(time)
end

#builds_with_any_tags(relation) ⇒ Object


67
68
69
# File 'app/services/ci/queue/build_queue_service.rb', line 67

def builds_with_any_tags(relation)
  strategy.builds_with_any_tags(relation)
end

#execute(relation) ⇒ Object


75
76
77
# File 'app/services/ci/queue/build_queue_service.rb', line 75

def execute(relation)
  strategy.build_ids(relation)
end

#new_buildsObject


14
15
16
# File 'app/services/ci/queue/build_queue_service.rb', line 14

def new_builds
  strategy.new_builds
end

#order(relation) ⇒ Object


71
72
73
# File 'app/services/ci/queue/build_queue_service.rb', line 71

def order(relation)
  strategy.order(relation)
end