File tree 2 files changed +13
-7
lines changed
2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -57,11 +57,14 @@ def debounce(*params, key_or_args_indices:)
57
57
# @param [NilClass|String] key
58
58
# @return [False|*] true if should be excecuted
59
59
def run ( key )
60
- return false unless let_in? ( key )
61
-
62
- yield . tap do
63
- redis . call ( 'DEL' , key )
64
- end
60
+ timestamp = nil
61
+ return false unless let_in? ( key ) { |t | timestamp = t }
62
+
63
+ redis . call ( 'DEL' , key )
64
+ yield
65
+ rescue StandardError => e
66
+ redis . call ( 'SET' , key , timestamp )
67
+ raise e
65
68
end
66
69
67
70
# @param [NilClass|String] key
@@ -75,7 +78,10 @@ def let_in?(key)
75
78
# the span of DELAY_BUFFER. The first one will clear the timestamp, and the rest
76
79
# will skip when they see that the timestamp is gone.
77
80
timestamp = redis . call ( 'GET' , key )
78
- return false if timestamp . nil? || now_i < timestamp . to_i
81
+ return false if timestamp . nil?
82
+
83
+ yield timestamp if block_given?
84
+ return false if now_i < timestamp . to_i
79
85
80
86
true
81
87
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module SidekiqBouncer
4
- VERSION = '0.3.3 '
4
+ VERSION = '0.3.4 '
5
5
end
You can’t perform that action at this time.
0 commit comments