From d8dd25a60e7c96a24d33cfe1b93be09085a1b86c Mon Sep 17 00:00:00 2001
From: Dylan Griffith <dyl.griffith@gmail.com>
Date: Mon, 30 Apr 2018 17:25:49 +0400
Subject: [PATCH] Introduce Project#all_runners and use in
 Ci::UpdateBuildQueueService

---
 app/models/project.rb                         |  9 ++++++---
 app/services/ci/update_build_queue_service.rb | 10 +---------
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/app/models/project.rb b/app/models/project.rb
index 5c9bf8c61dd..8abbb92da62 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1304,10 +1304,13 @@ class Project < ActiveRecord::Base
     @group_runners ||= group_runners_enabled? ? Ci::Runner.belonging_to_parent_group_of_project(self.id) : Ci::Runner.none
   end
 
+  def all_runners
+    union = Gitlab::SQL::Union.new([runners, group_runners, shared_runners])
+    Ci::Runner.from("(#{union.to_sql}) ci_runners")
+  end
+
   def any_runners?(&block)
-    union = Gitlab::SQL::Union.new([runners, shared_runners, group_runners])
-    runners = Ci::Runner.from("(#{union.to_sql}) ci_runners").active
-    runners.any?(&block)
+    all_runners.active.any?(&block)
   end
 
   def valid_runners_token?(token)
diff --git a/app/services/ci/update_build_queue_service.rb b/app/services/ci/update_build_queue_service.rb
index c991f04ab30..674782df00e 100644
--- a/app/services/ci/update_build_queue_service.rb
+++ b/app/services/ci/update_build_queue_service.rb
@@ -1,15 +1,7 @@
 module Ci
   class UpdateBuildQueueService
     def execute(build)
-      tick_for(build, build.project.runners)
-
-      if build.project.group_runners_enabled?
-        tick_for(build, Ci::Runner.belonging_to_parent_group_of_project(build.project_id))
-      end
-
-      if build.project.shared_runners_enabled?
-        tick_for(build, Ci::Runner.shared)
-      end
+      tick_for(build, build.project.all_runners)
     end
 
     private
-- 
2.30.9