diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-02-26 16:22:32 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-02-26 16:22:32 +0300 |
commit | 7403ea37ade3f96e8dae296551ed986bfcbaf138 (patch) | |
tree | 791bae3031f3b6022397be8d9674a427d836fe16 /lib | |
parent | ce6974eb1f7e8b3061ccffb5c4e6e98c9d26ab2c (diff) | |
parent | 56af2dbe7369575a5b7a1fb5202b728d6015846b (diff) |
Merge branch 'dm-waitable-worker' into 'master'
Extract WaitableWorker out of AuthorizedProjectsWorker
See merge request gitlab-org/gitlab-ce!17356
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 = [] |