summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-04-20 19:59:27 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2018-04-20 19:59:27 +0200
commit7e12212275969f5002f79656107e279169dbf560 (patch)
tree75b3e8aa99e3ebb2b794578486838eaee2e029bc
parentbbbf7138987c58454ac5f22d879b23bdc5bc60e7 (diff)
downloadgitlab-ce-use-redis-for-ci-queueing.tar.gz
-rw-r--r--lib/gitlab/ci/queueing/runner_queue.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/gitlab/ci/queueing/runner_queue.rb b/lib/gitlab/ci/queueing/runner_queue.rb
index 9ae8cda8beb..e6543b737dc 100644
--- a/lib/gitlab/ci/queueing/runner_queue.rb
+++ b/lib/gitlab/ci/queueing/runner_queue.rb
@@ -28,18 +28,27 @@ module Gitlab
def enqueue(build)
with_redis do |redis|
- redis.rpush(queue_project_key(build.project_id), build_id)
+ return if enqueued?(build)
+
+ redis.rpush(queue_project_key(build.project_id), build.id)
redis.rpush(queue_jobs_key(queue_job_bucket(build.project_id)), build.project_id)
end
end
+ def enqueued?(build)
+ queue_jobs_keys.any? do |queue_key|
+ redis.lindex(queue_key, build.id)
+ end
+ end
+
def dequeue
with_redis do |redis|
# We use circular list
# Runner once job is picked it is gonna be removed from the list
queue_jobs_keys.sample.each do |queue_key|
# TODO: instead of pop, we could grab
- # a random index from that list it would make it spread more evenly
+ # a random index from that list
+ # as it would make it spread more evenly
project_id = redis.brpoplpush(queue_key, queue_key)
next unless project_id
@@ -47,6 +56,7 @@ module Gitlab
unless build_id
# We don't have any builds for this project,
# we should remove it from the list
+ # !! unlikely to happen, but it will !!
redis.lrem(queue_key, 1, project_id)
next
end