Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace Configuration Env Vars with Backwards Compatibility #1046

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
master (unreleased)
===================
* Allow namespaced configuration env vars with `DELAYED_JOB_`-prefix
* Deprecate non-namespaced configuration env vars

4.1.5 - 2018-04-13
=================
* Allow Rails 5.2
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,11 @@ cancel the rake task with `CTRL-C`.

If you want to just run all available jobs and exit you can use `rake jobs:workoff`

Work off queues by setting the `QUEUE` or `QUEUES` environment variable.
Work off queues by setting the `DELAYED_JOB_QUEUE` or `DELAYED_JOB_QUEUES`
environment variable.

QUEUE=tracking rake jobs:work
QUEUES=mailers,tasks rake jobs:work
DELAYED_JOB_QUEUE=tracking rake jobs:work
DELAYED_JOB_QUEUES=mailers,tasks rake jobs:work

Restarting delayed_job
======================
Expand Down
22 changes: 16 additions & 6 deletions lib/delayed/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@
end

task :environment_options => :environment do
def read_env(name)
return ::ENV[name] if ::ENV.key?(name)

deprecated_name = name[/DELAYED_JOB_(.+)/, 1]
return unless ::ENV.key?(deprecated_name)

warn "[DEPRECATION] '#{deprecated_name}' for configuration is deprecated. Use '#{name}'"
::ENV[deprecated_name]
end

@worker_options = {
:min_priority => ENV['MIN_PRIORITY'],
:max_priority => ENV['MAX_PRIORITY'],
:queues => (ENV['QUEUES'] || ENV['QUEUE'] || '').split(','),
:quiet => ENV['QUIET']
:min_priority => read_env('DELAYED_JOB_MIN_PRIORITY'),
:max_priority => read_env('DELAYED_JOB_MAX_PRIORITY'),
:queues => (read_env('DELAYED_JOB_QUEUES') || read_env('DELAYED_JOB_QUEUE') || '').split(','),
:quiet => read_env('DELAYED_JOB_QUIET')
}

@worker_options[:sleep_delay] = ENV['SLEEP_DELAY'].to_i if ENV['SLEEP_DELAY']
@worker_options[:read_ahead] = ENV['READ_AHEAD'].to_i if ENV['READ_AHEAD']
@worker_options[:sleep_delay] = read_env('DELAYED_JOB_SLEEP_DELAY').to_i if read_env('DELAYED_JOB_SLEEP_DELAY')
@worker_options[:read_ahead] = read_env('DELAYED_JOB_READ_AHEAD').to_i if read_env('DELAYED_JOB_READ_AHEAD')
end

desc "Exit with error status if any jobs older than max_age seconds haven't been attempted yet."
Expand Down