diff options
author | Douwe Maan <douwe@selenight.nl> | 2018-02-26 14:17:50 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2018-02-26 15:25:58 +0300 |
commit | 1751cab41fb48fb4c231bfea9f3ab334ba98fea5 (patch) | |
tree | 0868db70e2d137e16cd9c5299d22166f14c20b84 /lib | |
parent | 58a312f5097b30a93100de93d06427402d514b48 (diff) |
Extract WaitableWorker out of AuthorizedProjectsWorker
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/job_waiter.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/gitlab/job_waiter.rb b/lib/gitlab/job_waiter.rb index f654508c391..f7a8eae0be4 100644 --- a/lib/gitlab/job_waiter.rb +++ b/lib/gitlab/job_waiter.rb @@ -15,16 +15,22 @@ module Gitlab # push to that array when done. Once the waiter has popped `count` items, it # knows all the jobs are done. class JobWaiter + KEY_PREFIX = "gitlab:job_waiter".freeze + def self.notify(key, jid) Gitlab::Redis::SharedState.with { |redis| redis.lpush(key, jid) } end + def self.key?(key) + key.is_a?(String) && key =~ /\A#{KEY_PREFIX}:\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/ + end + attr_reader :key, :finished attr_accessor :jobs_remaining # jobs_remaining - the number of jobs left to wait for # key - The key of this waiter. - def initialize(jobs_remaining = 0, key = "gitlab:job_waiter:#{SecureRandom.uuid}") + def initialize(jobs_remaining = 0, key = "#{KEY_PREFIX}:#{SecureRandom.uuid}") @key = key @jobs_remaining = jobs_remaining @finished = [] |