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

update_pending_build_service.rb « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d546dbcfe3d8ceeff02fae94622b82d260621323 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

module Ci
  class UpdatePendingBuildService
    VALID_PARAMS = %i[instance_runners_enabled namespace_id namespace_traversal_ids].freeze

    InvalidParamsError = Class.new(StandardError)
    InvalidModelError = Class.new(StandardError)

    def initialize(model, update_params)
      @model = model
      @update_params = update_params

      validations!
    end

    def execute
      return unless ::Feature.enabled?(:ci_pending_builds_maintain_shared_runners_data, @model, default_enabled: :yaml)

      @model.pending_builds.each_batch do |relation|
        relation.update_all(@update_params)
      end
    end

    private

    def validations!
      validate_model! && validate_params!
    end

    def validate_model!
      raise InvalidModelError unless @model.is_a?(::Project) || @model.is_a?(::Group)

      true
    end

    def validate_params!
      extra_params = @update_params.keys - VALID_PARAMS

      raise InvalidParamsError, "Unvalid params: #{extra_params.join(', ')}" unless extra_params.empty?

      true
    end
  end
end