2018-08-03 03:15:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-02 11:43:20 -04:00
|
|
|
module Ci
|
2019-03-28 09:17:42 -04:00
|
|
|
class RunnerNamespace < ApplicationRecord
|
2018-05-02 11:43:20 -04:00
|
|
|
extend Gitlab::Ci::Model
|
2021-05-05 17:09:59 -04:00
|
|
|
include Limitable
|
|
|
|
|
|
|
|
self.limit_name = 'ci_registered_group_runners'
|
|
|
|
self.limit_scope = :group
|
2021-06-02 11:09:59 -04:00
|
|
|
self.limit_relation = :recent_runners
|
2021-05-05 17:09:59 -04:00
|
|
|
self.limit_feature_flag = :ci_runner_limits
|
2018-05-02 11:43:20 -04:00
|
|
|
|
2021-02-22 10:10:48 -05:00
|
|
|
belongs_to :runner, inverse_of: :runner_namespaces
|
2018-05-28 07:07:28 -04:00
|
|
|
belongs_to :namespace, inverse_of: :runner_namespaces, class_name: '::Namespace'
|
2018-05-02 11:43:20 -04:00
|
|
|
belongs_to :group, class_name: '::Group', foreign_key: :namespace_id
|
2018-05-28 08:36:47 -04:00
|
|
|
|
|
|
|
validates :runner_id, uniqueness: { scope: :namespace_id }
|
2021-02-22 10:10:48 -05:00
|
|
|
validate :group_runner_type
|
|
|
|
|
2021-06-02 11:09:59 -04:00
|
|
|
def recent_runners
|
|
|
|
::Ci::Runner.belonging_to_group(namespace_id).recent
|
|
|
|
end
|
|
|
|
|
2021-02-22 10:10:48 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def group_runner_type
|
|
|
|
errors.add(:runner, 'is not a group runner') unless runner&.group_type?
|
|
|
|
end
|
2018-05-02 11:43:20 -04:00
|
|
|
end
|
|
|
|
end
|