diff options
Diffstat (limited to 'app/models/ci/runner.rb')
-rw-r--r-- | app/models/ci/runner.rb | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 4aa232ad26b..2f718ad7582 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -51,7 +51,7 @@ module Ci has_many :runner_projects, inverse_of: :runner, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :projects, through: :runner_projects has_many :runner_namespaces, inverse_of: :runner, autosave: true - has_many :groups, through: :runner_namespaces + has_many :groups, through: :runner_namespaces, disable_joins: true has_one :last_build, -> { order('id DESC') }, class_name: 'Ci::Build' @@ -246,7 +246,7 @@ module Ci begin transaction do - self.projects << project + self.runner_projects << ::Ci::RunnerProject.new(project: project, runner: self) self.save! end rescue ActiveRecord::RecordInvalid => e @@ -280,7 +280,7 @@ module Ci end def belongs_to_more_than_one_project? - self.projects.limit(2).count(:all) > 1 + runner_projects.limit(2).count(:all) > 1 end def assigned_to_group? @@ -309,7 +309,9 @@ module Ci end def only_for?(project) - projects == [project] + ::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/338659') do + projects == [project] + end end def short_sha @@ -344,7 +346,7 @@ module Ci # intention here is not to execute `Ci::RegisterJobService#execute` on # the primary database. # - ::Gitlab::Database::LoadBalancing::Sticking.stick(:runner, id) + ::Ci::Runner.sticking.stick(:runner, id) SecureRandom.hex.tap do |new_update| ::Gitlab::Workhorse.set_key_and_notify(runner_queue_key, new_update, @@ -428,10 +430,8 @@ module Ci end def no_projects - ::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/338659') do - if projects.any? - errors.add(:runner, 'cannot have projects assigned') - end + if runner_projects.any? + errors.add(:runner, 'cannot have projects assigned') end end @@ -444,14 +444,16 @@ module Ci end def any_project - unless projects.any? + unless runner_projects.any? errors.add(:runner, 'needs to be assigned to at least one project') end end def exactly_one_group - unless groups.one? - errors.add(:runner, 'needs to be assigned to exactly one group') + ::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/338659') do + unless groups.one? + errors.add(:runner, 'needs to be assigned to exactly one group') + end end end |