You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Multiple jobs can still be scheduled within the perform_in interval if being scheduled in a multithreaded environment.
Here is some sample code to reproduce issue:
# create a simple debounced worker
class DebouncedWorkerJob
include Sidekiq::Worker
sidekiq_options debounce: true
def perform(id)
puts "performing work with #{id}"
end
end
# var on main thread so threads block until flipped
wait_for_it = true
# significant enough concurrency to force issue
concurrency_level = 10
# store all jids from perform_in calls
jids = []
# initialize threads
threads = concurrency_level.times.map do |i|
Thread.new do
# block until flag is flipped
true while wait_for_it
# schedule debounced job, expectation is all but 1 return nil
jids[i] = DebouncedWorkerJob.perform_in(10.seconds, 1)
end
end
# flip flag so all threads unblock
wait_for_it = false
# wait for threads to finish
threads.each(&:join)
# count how many scheduled job ids we got back
scheduled_jobs = jids.reduce(0) { |acc, jid| jid.present? ? acc + 1 : acc }
# print out how many were scheduled, routinely returns 2 or 3 jobs scheduled even with debounce enabled
puts "Scheduled #{scheduled_jobs} jobs, expected 1"
The text was updated successfully, but these errors were encountered:
Multiple jobs can still be scheduled within the perform_in interval if being scheduled in a multithreaded environment.
Here is some sample code to reproduce issue:
The text was updated successfully, but these errors were encountered: