play_build_service.rb 462 Bytes
Newer Older
1 2
# frozen_string_literal: true

3 4 5
module Ci
  class PlayBuildService < ::BaseService
    def execute(build)
6
      unless can?(current_user, :update_build, build)
7 8 9
        raise Gitlab::Access::AccessDeniedError
      end

10
      # Try to enqueue the build, otherwise create a duplicate.
11 12 13 14 15 16 17 18 19
      #
      if build.enqueue
        build.tap { |action| action.update(user: current_user) }
      else
        Ci::Build.retry(build, current_user)
      end
    end
  end
end