Commit 333bbf8d authored by Yorick Peterse's avatar Yorick Peterse

Move EE code out of Gitlab::ExclusiveLease

This moves all EE specific code out of Gitlab::ExclusiveLease and into
EE::Gitlab::ExclusiveLease.
parent f10bd091
# frozen_string_literal: true
module EE
module Gitlab
module ExclusiveLease
# Try to obtain the lease. Returns the UUID and current TTL, which will be
# zero if it's not taken.
# rubocop: disable Gitlab/ModuleWithInstanceVariables
def try_obtain_with_ttl
::Gitlab::Redis::SharedState.with do |redis|
output = redis.set(@redis_shared_state_key, @uuid, nx: true, ex: @timeout) && @uuid
ttl = output ? 0 : redis.ttl(@redis_shared_state_key)
{ ttl: [ttl, 0].max, uuid: output }
end
end
# rubocop: enable Gitlab/ModuleWithInstanceVariables
# Returns true if the UUID for the key hasn't changed.
# rubocop: disable Gitlab/ModuleWithInstanceVariables
def same_uuid?
::Gitlab::Redis::SharedState.with do |redis|
redis.get(@redis_shared_state_key) == @uuid
end
end
# rubocop: enable Gitlab/ModuleWithInstanceVariables
end
end
end
......@@ -68,18 +68,6 @@ module Gitlab
end
end
# Try to obtain the lease. Returns the UUID and current TTL, which will be
# zero if it's not taken.
def try_obtain_with_ttl
Gitlab::Redis::SharedState.with do |redis|
output = redis.set(@redis_shared_state_key, @uuid, nx: true, ex: @timeout) && @uuid
ttl = output ? 0 : redis.ttl(@redis_shared_state_key)
{ ttl: [ttl, 0].max, uuid: output }
end
end
# Try to renew an existing lease. Return lease UUID on success,
# false if the lease is taken by a different UUID or inexistent.
def renew
......@@ -106,12 +94,7 @@ module Gitlab
ttl if ttl.positive?
end
end
# Returns true if the UUID for the key hasn't changed.
def same_uuid?
Gitlab::Redis::SharedState.with do |redis|
redis.get(@redis_shared_state_key) == @uuid
end
end
end
end
Gitlab::ExclusiveLease.prepend(EE::Gitlab::ExclusiveLease)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment