Skip to content

Commit 2868f02

Browse files
authored
Explicitly configure worker sleep delay (#4149)
The default worker sleep delay in delayed_job is 5 seconds. Reducing this value could reduce the database load when there aren't many jobs to process.
1 parent 0d37cbe commit 2868f02

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed

config/cloud_controller.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ system_hostnames:
3333
jobs:
3434
global:
3535
timeout_in_seconds: 14400
36+
worker_sleep_delay_in_seconds: 5
3637
queues: {}
3738

3839
app_usage_events:

lib/cloud_controller/config_schemas/base/api_schema.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,10 @@ class ApiSchema < VCAP::Config
335335
default_app_ssh_access: bool,
336336

337337
jobs: {
338-
global: { timeout_in_seconds: Integer },
338+
global: {
339+
timeout_in_seconds: Integer,
340+
worker_sleep_delay_in_seconds: Integer
341+
},
339342
queues: {
340343
optional(:cc_generic) => { timeout_in_seconds: Integer }
341344
},

lib/cloud_controller/config_schemas/base/worker_schema.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ class WorkerSchema < VCAP::Config
161161
default_app_ssh_access: bool,
162162

163163
jobs: {
164-
global: { timeout_in_seconds: Integer },
164+
global: {
165+
timeout_in_seconds: Integer,
166+
worker_sleep_delay_in_seconds: Integer
167+
},
165168
queues: {
166169
optional(:cc_generic) => { timeout_in_seconds: Integer }
167170
},

lib/delayed_job/delayed_worker.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def get_initialized_delayed_worker(config, logger)
4848
Delayed::Worker.destroy_failed_jobs = false
4949
Delayed::Worker.max_attempts = 3
5050
Delayed::Worker.max_run_time = config.get(:jobs, :global, :timeout_in_seconds) + 1
51+
Delayed::Worker.sleep_delay = config.get(:jobs, :global, :worker_sleep_delay_in_seconds)
5152
Delayed::Worker.logger = logger
5253

5354
unless @queue_options[:num_threads].nil?

spec/unit/lib/delayed_job/delayed_worker_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
expect(Delayed::Worker.destroy_failed_jobs).to be false
8484
expect(Delayed::Worker.max_attempts).to eq(3)
8585
expect(Delayed::Worker.max_run_time).to eq(14_401)
86+
expect(Delayed::Worker.sleep_delay).to eq(5)
8687
end
8788

8889
context 'when the number of threads is specified' do

0 commit comments

Comments
 (0)