summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/ci/build.rb6
-rw-r--r--app/workers/build_queue_worker.rb18
-rw-r--r--lib/ci/api/helpers.rb1
3 files changed, 25 insertions, 0 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 88c46076df6..cab9393344b 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -81,6 +81,12 @@ module Ci
end
state_machine :status do
+ after_transition any => [:pending] do |build|
+ build.run_after_commit do
+ BuildQueueWorker.perform_async(id)
+ end
+ end
+
after_transition pending: :running do |build|
build.run_after_commit do
BuildHooksWorker.perform_async(id)
diff --git a/app/workers/build_queue_worker.rb b/app/workers/build_queue_worker.rb
new file mode 100644
index 00000000000..f19290b0c1a
--- /dev/null
+++ b/app/workers/build_queue_worker.rb
@@ -0,0 +1,18 @@
+class BuildQueueWorker
+ include Sidekiq::Worker
+ include BuildQueue
+
+ def perform(build_id)
+ Ci::Build.find_by(id: build_id).try do |build|
+ project.runners.select do |runner|
+ if runner.can_pick?(build)
+ # Inject last_update into Redis
+ Gitlab::Redis.with do |redis]
+ new_update = Time.new.inspect
+ redis.set(current_runner_redis_key, new_update, ex: 60.minutes)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb
index ef80e0df5d3..74e1871619e 100644
--- a/lib/ci/api/helpers.rb
+++ b/lib/ci/api/helpers.rb
@@ -62,6 +62,7 @@ module Ci
def current_runner_redis_key
@runner_redis_key ||= "#{current_runner.token}_#{current_runner.tag_list}"
+ end
def get_runner_version_from_params
return unless params["info"].present?