Skip to content

Commit

Permalink
Explicitly configure worker sleep delay (#4149)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
johha authored Dec 19, 2024
1 parent 0d37cbe commit 2868f02
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/cloud_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ system_hostnames:
jobs:
global:
timeout_in_seconds: 14400
worker_sleep_delay_in_seconds: 5
queues: {}

app_usage_events:
Expand Down
5 changes: 4 additions & 1 deletion lib/cloud_controller/config_schemas/base/api_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ class ApiSchema < VCAP::Config
default_app_ssh_access: bool,

jobs: {
global: { timeout_in_seconds: Integer },
global: {
timeout_in_seconds: Integer,
worker_sleep_delay_in_seconds: Integer
},
queues: {
optional(:cc_generic) => { timeout_in_seconds: Integer }
},
Expand Down
5 changes: 4 additions & 1 deletion lib/cloud_controller/config_schemas/base/worker_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ class WorkerSchema < VCAP::Config
default_app_ssh_access: bool,

jobs: {
global: { timeout_in_seconds: Integer },
global: {
timeout_in_seconds: Integer,
worker_sleep_delay_in_seconds: Integer
},
queues: {
optional(:cc_generic) => { timeout_in_seconds: Integer }
},
Expand Down
1 change: 1 addition & 0 deletions lib/delayed_job/delayed_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def get_initialized_delayed_worker(config, logger)
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.max_attempts = 3
Delayed::Worker.max_run_time = config.get(:jobs, :global, :timeout_in_seconds) + 1
Delayed::Worker.sleep_delay = config.get(:jobs, :global, :worker_sleep_delay_in_seconds)
Delayed::Worker.logger = logger

unless @queue_options[:num_threads].nil?
Expand Down
1 change: 1 addition & 0 deletions spec/unit/lib/delayed_job/delayed_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
expect(Delayed::Worker.destroy_failed_jobs).to be false
expect(Delayed::Worker.max_attempts).to eq(3)
expect(Delayed::Worker.max_run_time).to eq(14_401)
expect(Delayed::Worker.sleep_delay).to eq(5)
end

context 'when the number of threads is specified' do
Expand Down

0 comments on commit 2868f02

Please sign in to comment.