Skip to content

Commit 1e593fe

Browse files
committed
ensure failed tasks run again
1 parent 5dcafe0 commit 1e593fe

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/sidekiq_bouncer/bouncer.rb

+12-6
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ def debounce(*params, key_or_args_indices:)
5757
# @param [NilClass|String] key
5858
# @return [False|*] true if should be excecuted
5959
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
6568
end
6669

6770
# @param [NilClass|String] key
@@ -75,7 +78,10 @@ def let_in?(key)
7578
# the span of DELAY_BUFFER. The first one will clear the timestamp, and the rest
7679
# will skip when they see that the timestamp is gone.
7780
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
7985

8086
true
8187
end

lib/sidekiq_bouncer/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module SidekiqBouncer
4-
VERSION = '0.3.3'
4+
VERSION = '0.3.4'
55
end

0 commit comments

Comments
 (0)