debian-mirror-gitlab/app/services/ci/enqueue_job_service.rb
2023-03-05 14:24:40 +05:30

25 lines
618 B
Ruby

# frozen_string_literal: true
module Ci
class EnqueueJobService
attr_accessor :job, :current_user, :variables
def initialize(job, current_user:, variables: nil)
@job = job
@current_user = current_user
@variables = variables
end
def execute(&transition)
job.user = current_user
job.job_variables_attributes = variables if variables
transition ||= ->(job) { job.enqueue! }
Gitlab::OptimisticLocking.retry_lock(job, name: 'ci_enqueue_job', &transition)
ResetSkippedJobsService.new(job.project, current_user).execute(job)
job
end
end
end