summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-02-26 13:22:32 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-02-26 13:22:32 +0000
commit7403ea37ade3f96e8dae296551ed986bfcbaf138 (patch)
tree791bae3031f3b6022397be8d9674a427d836fe16 /lib
parentce6974eb1f7e8b3061ccffb5c4e6e98c9d26ab2c (diff)
parent56af2dbe7369575a5b7a1fb5202b728d6015846b (diff)
downloadgitlab-ce-7403ea37ade3f96e8dae296551ed986bfcbaf138.tar.gz
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.rb8
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 = []