From 200beb5dc2f3f727a4e5ef8e341590373ac30159 Mon Sep 17 00:00:00 2001 From: smudge Date: Wed, 18 Dec 2024 11:53:29 -0500 Subject: [PATCH] Default to 0 (until v1.0) and document in README --- README.md | 4 ++++ lib/delayed/worker.rb | 2 +- spec/helper.rb | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd9f292..beab83e 100644 --- a/README.md +++ b/README.md @@ -432,6 +432,10 @@ Delayed::Worker.read_ahead = 5 # If a worker finds no jobs, it will sleep this number of seconds in between attempts: Delayed::Worker.sleep_delay = 5 + +# Until version 1.0, the worker will not sleep at all between attemps if it finds jobs. +# This can be configured by setting the minimum reserve interval: +Delayed::Worker.min_reserve_interval = 0.5 # seconds ``` If a job fails, it will be rerun up to 25 times (with an exponential back-off). Jobs will also diff --git a/lib/delayed/worker.rb b/lib/delayed/worker.rb index b2ca131..c8cff37 100644 --- a/lib/delayed/worker.rb +++ b/lib/delayed/worker.rb @@ -12,7 +12,7 @@ class Worker include Runnable cattr_accessor :sleep_delay, instance_writer: false, default: 5 - cattr_accessor :min_reserve_interval, instance_writer: false, default: 1 + cattr_accessor :min_reserve_interval, instance_writer: false, default: 0 cattr_accessor :max_attempts, instance_writer: false, default: 25 cattr_accessor :max_claims, instance_writer: false, default: 5 cattr_accessor :max_run_time, instance_writer: false, default: 20.minutes diff --git a/spec/helper.rb b/spec/helper.rb index 6ad9993..baec590 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -120,6 +120,10 @@ class SingletonClass sleep_delay_was = Delayed::Worker.sleep_delay min_reserve_interval_was = Delayed::Worker.min_reserve_interval + if Gem.loaded_specs['delayed'].version >= Gem::Version.new('1.0') && min_reserve_interval_was.zero? + raise "Min reserve interval should be nonzero in v1.0 release" + end + Delayed::Worker.sleep_delay = TEST_SLEEP_DELAY Delayed::Worker.min_reserve_interval = TEST_MIN_RESERVE_INTERVAL