2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
module Ci
|
2021-10-27 15:23:28 +05:30
|
|
|
class RunnerNamespace < Ci::ApplicationRecord
|
2021-06-08 01:23:25 +05:30
|
|
|
include Limitable
|
|
|
|
|
|
|
|
self.limit_name = 'ci_registered_group_runners'
|
|
|
|
self.limit_scope = :group
|
2021-09-04 01:27:46 +05:30
|
|
|
self.limit_relation = :recent_runners
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
belongs_to :runner, inverse_of: :runner_namespaces
|
2018-11-08 19:23:39 +05:30
|
|
|
belongs_to :namespace, inverse_of: :runner_namespaces, class_name: '::Namespace'
|
2018-10-15 14:42:47 +05:30
|
|
|
belongs_to :group, class_name: '::Group', foreign_key: :namespace_id
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
validates :runner_id, uniqueness: { scope: :namespace_id }
|
2021-04-17 20:07:23 +05:30
|
|
|
validate :group_runner_type
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
scope :for_runner, ->(runner_id) { where(runner_id: runner_id) }
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
def recent_runners
|
|
|
|
::Ci::Runner.belonging_to_group(namespace_id).recent
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def group_runner_type
|
|
|
|
errors.add(:runner, 'is not a group runner') unless runner&.group_type?
|
|
|
|
end
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
|
|
|
end
|