lib/suo/client/base.rb in suo-0.3.2 vs lib/suo/client/base.rb in suo-0.3.3
- old
+ new
@@ -3,11 +3,12 @@
class Base
DEFAULT_OPTIONS = {
acquisition_timeout: 0.1,
acquisition_delay: 0.01,
stale_lock_expiration: 3600,
- resources: 1
+ resources: 1,
+ ttl: 60,
}.freeze
BLANK_STR = "".freeze
attr_accessor :client, :key, :resources, :options
@@ -53,20 +54,17 @@
def refresh(token)
retry_with_timeout do
val, cas = get
- if val.nil?
- initial_set
- next
- end
+ cas = initial_set if val.nil?
cleared_locks = deserialize_and_clear_locks(val)
refresh_lock(cleared_locks, token)
- break if set(serialize_locks(cleared_locks), cas)
+ break if set(serialize_locks(cleared_locks), cas, expire: cleared_locks.empty?)
end
end
def unlock(token)
return unless token
@@ -79,11 +77,11 @@
cleared_locks = deserialize_and_clear_locks(val)
acquisition_lock = remove_lock(cleared_locks, token)
break unless acquisition_lock
- break if set(serialize_locks(cleared_locks), cas)
+ break if set(serialize_locks(cleared_locks), cas, expire: cleared_locks.empty?)
end
rescue LockClientError => _ # rubocop:disable Lint/HandleExceptions
# ignore - assume success due to optimistic locking
end
@@ -99,13 +97,10 @@
token ||= SecureRandom.base64(16)
retry_with_timeout do
val, cas = get
- if val.nil?
- initial_set
- next
- end
+ cas = initial_set if val.nil?
cleared_locks = deserialize_and_clear_locks(val)
if cleared_locks.size < resources
add_lock(cleared_locks, token)