Class: Ci::RegisterJobService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Ci::Artifacts::Logger
Defined in:
app/services/ci/register_job_service.rb,
app/services/ci/register_job_service/logger.rb

Overview

This class responsible for assigning proper pending build to runner on runner API request

Defined Under Namespace

Classes: Logger, Result, ResultFactory

Constant Summary collapse

TEMPORARY_LOCK_TIMEOUT =
3.seconds
MAX_QUEUE_DEPTH =

The queue depth limit number has been determined by observing 95 percentile of effective queue depth on gitlab.com. This is only likely to affect 5% of the worst case scenarios.

45

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Ci::Artifacts::Logger

#log_artifacts_context, #log_artifacts_filesize, #log_build_dependencies, log_created, log_deleted

Constructor Details

#initialize(runner, runner_manager) ⇒ RegisterJobService

Returns a new instance of RegisterJobService.



46
47
48
49
50
51
# File 'app/services/ci/register_job_service.rb', line 46

def initialize(runner, runner_manager)
  @runner = runner
  @runner_manager = runner_manager
  @metrics = ::Gitlab::Ci::Queue::Metrics.new(runner)
  @logger = ::Ci::RegisterJobService::Logger.new(runner: runner)
end

Instance Attribute Details

#metricsObject (readonly)

Returns the value of attribute metrics.



9
10
11
# File 'app/services/ci/register_job_service.rb', line 9

def metrics
  @metrics
end

#runnerObject (readonly)

Returns the value of attribute runner.



9
10
11
# File 'app/services/ci/register_job_service.rb', line 9

def runner
  @runner
end

#runner_managerObject (readonly)

Returns the value of attribute runner_manager.



9
10
11
# File 'app/services/ci/register_job_service.rb', line 9

def runner_manager
  @runner_manager
end

Instance Method Details

#execute(params = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/services/ci/register_job_service.rb', line 53

def execute(params = {})
  @replica_caught_up =
    ::Ci::Runner.sticking.find_caught_up_replica(:runner, runner.id, use_primary_on_failure: false)

  @metrics.increment_queue_operation(:queue_attempt)

  result = process_queue_with_instrumentation(params)

  # Since we execute this query against replica it might lead to false-positive
  # We might receive the positive response: "hi, we don't have any more builds for you".
  # This might not be true. If our DB replica is not up-to date with when runner event was generated
  # we might still have some CI builds to be picked. Instead we should say to runner:
  # "Hi, we don't have any more builds now,  but not everything is right anyway, so try again".
  # Runner will retry, but again, against replica, and again will check if replication lag did catch-up.
  if !@replica_caught_up && !result.build
    metrics.increment_queue_operation(:queue_replication_lag)

    ResultFactory.invalid
  else
    result
  end

ensure
  @logger.commit
end