Welcome to mirror list, hosted at ThFree Co, Russian Federation.

enqueue_job_service.rb « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: db616473336937e8649c6f76bb646992e2f0afe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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)
      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
  end
end