Class: Ci::RetryJobService

Inherits:
BaseService show all
Includes:
Gitlab::InternalEventsTracking, Gitlab::Utils::StrongMemoize
Defined in:
app/services/ci/retry_job_service.rb

Constant Summary

Constants inherited from BaseService

BaseService::UnauthorizedError

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::InternalEventsTracking

#track_internal_event

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#clone!(job, variables: [], inputs: {}, enqueue_if_actionable: false, start_pipeline: false) ⇒ Object

Raises:

  • (TypeError)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/services/ci/retry_job_service.rb', line 27

def clone!(job, variables: [], inputs: {}, enqueue_if_actionable: false, start_pipeline: false)
  # Cloning a job requires a strict type check to ensure
  # the attributes being used for the clone are taken straight
  # from the model and not overridden by other abstractions.
  raise TypeError unless job.instance_of?(Ci::Build) || job.instance_of?(Ci::Bridge)

  check_access!(job)
  variables = ensure_project_id!(variables)

  new_job = Ci::CloneJobService.new(job, current_user: current_user).execute(
    new_job_variables: variables,
    new_job_inputs: inputs
  )

  if enqueue_if_actionable && new_job.action?
    new_job.set_enqueue_immediately!
  end

  start_pipeline_proc = -> { start_pipeline(job, new_job) } if start_pipeline

  new_job.run_after_commit do
    new_job.link_to_environment(job.persisted_environment) if job.persisted_environment.present?

    start_pipeline_proc&.call

    ::Ci::CopyCrossDatabaseAssociationsService.new.execute(job, new_job)

    ::MergeRequests::AddTodoWhenBuildFailsService
      .new(project: project)
      .close(new_job)
  end

  add_job = -> do
    ::Ci::Pipelines::AddJobService.new(job.pipeline).execute!(new_job) do |processable|
      BulkInsertableAssociations.with_bulk_insert do
        processable.save!
      end
    end
  end

  add_job.call

  job.reset # refresh the data to get new values of `retried` and `processed`.

  new_job
end

#execute(job, variables: [], inputs: {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/ci/retry_job_service.rb', line 8

def execute(job, variables: [], inputs: {})
  if job.retryable?
    processed_inputs = process_job_inputs(job, inputs)
    return processed_inputs if processed_inputs.error?

    job.ensure_scheduling_type!
    new_job = retry_job(job, variables: variables, inputs: processed_inputs.payload[:inputs])

    track_retry_with_new_input_values(processed_inputs.payload[:inputs])

    ServiceResponse.success(payload: { job: new_job })
  else
    ServiceResponse.error(
      message: 'Job is not retryable',
      payload: { job: job, reason: :not_retryable }
    )
  end
end