Class: Ci::Pipelines::AddJobService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::ExclusiveLeaseHelpers
Defined in:
app/services/ci/pipelines/add_job_service.rb

Constant Summary

Constants included from Gitlab::ExclusiveLeaseHelpers

Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::ExclusiveLeaseHelpers

#in_lock

Constructor Details

#initialize(pipeline) ⇒ AddJobService

Returns a new instance of AddJobService.

Raises:

  • (ArgumentError)


10
11
12
13
14
# File 'app/services/ci/pipelines/add_job_service.rb', line 10

def initialize(pipeline)
  @pipeline = pipeline

  raise ArgumentError, "Pipeline must be persisted for this service to be used" unless pipeline.persisted?
end

Instance Attribute Details

#pipelineObject (readonly)

Returns the value of attribute pipeline.



8
9
10
# File 'app/services/ci/pipelines/add_job_service.rb', line 8

def pipeline
  @pipeline
end

Instance Method Details

#execute!(job, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/ci/pipelines/add_job_service.rb', line 16

def execute!(job, &block)
  assign_pipeline_attributes(job)

  in_lock("ci:pipelines:#{pipeline.id}:add-job", ttl: LOCK_TIMEOUT, sleep_sec: LOCK_SLEEP, retries: LOCK_RETRIES) do
    Ci::Pipeline.transaction do
      yield(job)

      job.update_older_statuses_retried!
    end
  end

  ServiceResponse.success(payload: { job: job })
rescue StandardError => e
  ServiceResponse.error(message: e.message, payload: { job: job })
end