diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-09-04 18:55:04 +0100 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-09-07 18:52:04 +0100 |
commit | 39298575a819ade6ad4f9e37a7f22592a05d21f8 (patch) | |
tree | 43319ff3c1bb533e20c5185571aa7341be984f31 /lib | |
parent | 21935d85382989e38dd4cc12de55966e0c9b6eba (diff) | |
download | gitlab-ce-39298575a819ade6ad4f9e37a7f22592a05d21f8.tar.gz |
Adds exclusive lease to Git garbage collect worker.35558-only-one-garbage-collection-should-be-running-per-project-at-once
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/exclusive_lease.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/gitlab/exclusive_lease.rb b/lib/gitlab/exclusive_lease.rb index 3784f6c4947..3f7b42456af 100644 --- a/lib/gitlab/exclusive_lease.rb +++ b/lib/gitlab/exclusive_lease.rb @@ -25,6 +25,12 @@ module Gitlab end EOS + def self.get_uuid(key) + Gitlab::Redis::SharedState.with do |redis| + redis.get(redis_shared_state_key(key)) || false + end + end + def self.cancel(key, uuid) Gitlab::Redis::SharedState.with do |redis| redis.eval(LUA_CANCEL_SCRIPT, keys: [redis_shared_state_key(key)], argv: [uuid]) @@ -35,10 +41,10 @@ module Gitlab "gitlab:exclusive_lease:#{key}" end - def initialize(key, timeout:) + def initialize(key, uuid: nil, timeout:) @redis_shared_state_key = self.class.redis_shared_state_key(key) @timeout = timeout - @uuid = SecureRandom.uuid + @uuid = uuid || SecureRandom.uuid end # Try to obtain the lease. Return lease UUID on success, |