gitlab-org--gitlab-foss/app/models/ci/runner_namespace.rb

31 lines
891 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-05-02 15:43:20 +00:00
module Ci
class RunnerNamespace < Ci::ApplicationRecord
include Limitable
self.limit_name = 'ci_registered_group_runners'
self.limit_scope = :group
self.limit_relation = :recent_runners
self.limit_feature_flag = :ci_runner_limits
self.limit_feature_flag_for_override = :ci_runner_limits_override
2018-05-02 15:43:20 +00:00
belongs_to :runner, inverse_of: :runner_namespaces
2018-05-28 11:07:28 +00:00
belongs_to :namespace, inverse_of: :runner_namespaces, class_name: '::Namespace'
2018-05-02 15:43:20 +00:00
belongs_to :group, class_name: '::Group', foreign_key: :namespace_id
2018-05-28 12:36:47 +00:00
validates :runner_id, uniqueness: { scope: :namespace_id }
validate :group_runner_type
def recent_runners
::Ci::Runner.belonging_to_group(namespace_id).recent
end
private
def group_runner_type
errors.add(:runner, 'is not a group runner') unless runner&.group_type?
end
2018-05-02 15:43:20 +00:00
end
end