mirror of
https://github.com/dkam/suo.git
synced 2025-01-29 07:42:43 +00:00
check timeout at the entry of the loop
This commit is contained in:
@@ -16,7 +16,12 @@ module Suo
|
|||||||
begin
|
begin
|
||||||
start = Time.now.to_f
|
start = Time.now.to_f
|
||||||
|
|
||||||
options[:retry_count].times do |i|
|
options[:retry_count].times do
|
||||||
|
if options[:retry_timeout]
|
||||||
|
now = Time.now.to_f
|
||||||
|
break if now - start > options[:retry_timeout]
|
||||||
|
end
|
||||||
|
|
||||||
val, cas = client.get_cas(key)
|
val, cas = client.get_cas(key)
|
||||||
|
|
||||||
# no key has been set yet; we could simply set it, but would lead to race conditions on the initial setting
|
# no key has been set yet; we could simply set it, but would lead to race conditions on the initial setting
|
||||||
@@ -38,11 +43,6 @@ module Suo
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:retry_timeout]
|
|
||||||
now = Time.now.to_f
|
|
||||||
break if now - start > options[:retry_timeout]
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
||||||
end
|
end
|
||||||
rescue => _
|
rescue => _
|
||||||
@@ -60,6 +60,11 @@ module Suo
|
|||||||
start = Time.now.to_f
|
start = Time.now.to_f
|
||||||
|
|
||||||
options[:retry_count].times do
|
options[:retry_count].times do
|
||||||
|
if options[:retry_timeout]
|
||||||
|
now = Time.now.to_f
|
||||||
|
break if now - start > options[:retry_timeout]
|
||||||
|
end
|
||||||
|
|
||||||
val, cas = client.get_cas(key)
|
val, cas = client.get_cas(key)
|
||||||
|
|
||||||
# much like with initial set - ensure the key is here
|
# much like with initial set - ensure the key is here
|
||||||
@@ -76,11 +81,6 @@ module Suo
|
|||||||
|
|
||||||
break if client.set_cas(key, newval, cas)
|
break if client.set_cas(key, newval, cas)
|
||||||
|
|
||||||
if options[:retry_timeout]
|
|
||||||
now = Time.now.to_f
|
|
||||||
break if now - start > options[:retry_timeout]
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
||||||
end
|
end
|
||||||
rescue => _
|
rescue => _
|
||||||
@@ -98,6 +98,11 @@ module Suo
|
|||||||
start = Time.now.to_f
|
start = Time.now.to_f
|
||||||
|
|
||||||
options[:retry_count].times do
|
options[:retry_count].times do
|
||||||
|
if options[:retry_timeout]
|
||||||
|
now = Time.now.to_f
|
||||||
|
break if now - start > options[:retry_timeout]
|
||||||
|
end
|
||||||
|
|
||||||
val, cas = client.get_cas(key)
|
val, cas = client.get_cas(key)
|
||||||
|
|
||||||
break if val.nil? # lock has expired totally
|
break if val.nil? # lock has expired totally
|
||||||
@@ -114,11 +119,6 @@ module Suo
|
|||||||
|
|
||||||
# another client cleared a token in the interim - try again!
|
# another client cleared a token in the interim - try again!
|
||||||
|
|
||||||
if options[:retry_timeout]
|
|
||||||
now = Time.now.to_f
|
|
||||||
break if now - start > options[:retry_timeout]
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
||||||
end
|
end
|
||||||
rescue => boom # rubocop:disable Lint/HandleExceptions
|
rescue => boom # rubocop:disable Lint/HandleExceptions
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ module Suo
|
|||||||
start = Time.now.to_f
|
start = Time.now.to_f
|
||||||
|
|
||||||
options[:retry_count].times do
|
options[:retry_count].times do
|
||||||
|
if options[:retry_timeout]
|
||||||
|
now = Time.now.to_f
|
||||||
|
break if now - start > options[:retry_timeout]
|
||||||
|
end
|
||||||
|
|
||||||
client.watch(key) do
|
client.watch(key) do
|
||||||
begin
|
begin
|
||||||
val = client.get(key)
|
val = client.get(key)
|
||||||
@@ -41,15 +46,9 @@ module Suo
|
|||||||
|
|
||||||
break if acquisition_token
|
break if acquisition_token
|
||||||
|
|
||||||
if options[:retry_timeout]
|
|
||||||
now = Time.now.to_f
|
|
||||||
break if now - start > options[:retry_timeout]
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
||||||
end
|
end
|
||||||
rescue => boom
|
rescue => _
|
||||||
raise boom
|
|
||||||
raise Suo::Client::FailedToAcquireLock
|
raise Suo::Client::FailedToAcquireLock
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,6 +64,11 @@ module Suo
|
|||||||
start = Time.now.to_f
|
start = Time.now.to_f
|
||||||
|
|
||||||
options[:retry_count].times do
|
options[:retry_count].times do
|
||||||
|
if options[:retry_timeout]
|
||||||
|
now = Time.now.to_f
|
||||||
|
break if now - start > options[:retry_timeout]
|
||||||
|
end
|
||||||
|
|
||||||
client.watch(key) do
|
client.watch(key) do
|
||||||
begin
|
begin
|
||||||
val = client.get(key)
|
val = client.get(key)
|
||||||
@@ -87,11 +91,6 @@ module Suo
|
|||||||
|
|
||||||
break if refreshed
|
break if refreshed
|
||||||
|
|
||||||
if options[:retry_timeout]
|
|
||||||
now = Time.now.to_f
|
|
||||||
break if now - start > options[:retry_timeout]
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
||||||
end
|
end
|
||||||
rescue => _
|
rescue => _
|
||||||
@@ -111,6 +110,11 @@ module Suo
|
|||||||
options[:retry_count].times do
|
options[:retry_count].times do
|
||||||
cleared = false
|
cleared = false
|
||||||
|
|
||||||
|
if options[:retry_timeout]
|
||||||
|
now = Time.now.to_f
|
||||||
|
break if now - start > options[:retry_timeout]
|
||||||
|
end
|
||||||
|
|
||||||
client.watch(key) do
|
client.watch(key) do
|
||||||
begin
|
begin
|
||||||
val = client.get(key)
|
val = client.get(key)
|
||||||
@@ -144,11 +148,6 @@ module Suo
|
|||||||
|
|
||||||
break if cleared
|
break if cleared
|
||||||
|
|
||||||
if options[:retry_timeout]
|
|
||||||
now = Time.now.to_f
|
|
||||||
break if now - start > options[:retry_timeout]
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
sleep(rand(options[:retry_delay] * 1000).to_f / 1000)
|
||||||
end
|
end
|
||||||
rescue => boom # rubocop:disable Lint/HandleExceptions
|
rescue => boom # rubocop:disable Lint/HandleExceptions
|
||||||
|
|||||||
Reference in New Issue
Block a user