diff --git a/CHANGELOG.md b/CHANGELOG.md index f8e80c679..b7c14821d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 0d764ab4d..ab4f42527 100644 --- a/README.md +++ b/README.md @@ -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 ====================== diff --git a/lib/delayed/tasks.rb b/lib/delayed/tasks.rb index 409ba48f8..a54d128a3 100644 --- a/lib/delayed/tasks.rb +++ b/lib/delayed/tasks.rb @@ -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] + if ::ENV.key?(deprecated_name) + warn "[DEPRECATION] '#{deprecated_name}' for configuration is deprecated. Use '#{name}'" + ::ENV[deprecated_name] + end + 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."