Class: Ci::EnqueueJobService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ci/enqueue_job_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, current_user:, variables: nil) ⇒ EnqueueJobService

Returns a new instance of EnqueueJobService.



7
8
9
10
11
# File 'app/services/ci/enqueue_job_service.rb', line 7

def initialize(job, current_user:, variables: nil)
  @job = job
  @current_user = current_user
  @variables = variables
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.



5
6
7
# File 'app/services/ci/enqueue_job_service.rb', line 5

def current_user
  @current_user
end

#jobObject

Returns the value of attribute job.



5
6
7
# File 'app/services/ci/enqueue_job_service.rb', line 5

def job
  @job
end

#variablesObject

Returns the value of attribute variables.



5
6
7
# File 'app/services/ci/enqueue_job_service.rb', line 5

def variables
  @variables
end

Instance Method Details

#execute(&transition) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/ci/enqueue_job_service.rb', line 13

def execute(&transition)
  transition ||= ->(job) { job.enqueue! }

  Gitlab::OptimisticLocking.retry_lock(job, name: 'ci_enqueue_job') do |job|
    job.user = current_user
    job.job_variables_attributes = variables if variables

    transition.call(job)
  end

  ResetSkippedJobsService.new(job.project, current_user).execute(job)

  job
end