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

Add an --ontop arg to keep the process alive for heroku #725

Closed
wants to merge 4 commits into from
Closed
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ You can then do the following:
RAILS_ENV=production script/delayed_job start --exit-on-complete
# or to run in the foreground
RAILS_ENV=production script/delayed_job run --exit-on-complete

# --ontop: keep parent process around. Useful for Heroku dyno worker processes
# Passed the :ontop parameter to Daemonize
RAILS_ENV=production script/delayed_job --ontop -n 2 start


**Rails 4:** *replace script/delayed_job with bin/delayed_job*

Expand Down
8 changes: 6 additions & 2 deletions lib/delayed/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Command # rubocop:disable ClassLength
def initialize(args) # rubocop:disable MethodLength
@options = {
:quiet => true,
:pid_dir => "#{Rails.root}/tmp/pids"
:pid_dir => "#{Rails.root}/tmp/pids",
:ontop => false
}

@worker_count = 1
Expand Down Expand Up @@ -66,6 +67,9 @@ def initialize(args) # rubocop:disable MethodLength
opt.on('--pool=queue1[,queue2][:worker_count]', 'Specify queues and number of workers for a worker pool') do |pool|
parse_worker_pool(pool)
end
opt.on('--ontop', 'Specify :ontop to daemonize to persist the parent process. Helpful for Heroku to keep the dyno alive') do |ontop|
@options[:ontop] = true
end
opt.on('--exit-on-complete', 'Exit when no more jobs are available to run. This will exit if all jobs are scheduled to run in the future.') do
@options[:exit_on_complete] = true
end
Expand Down Expand Up @@ -107,7 +111,7 @@ def setup_pools

def run_process(process_name, options = {})
Delayed::Worker.before_fork
Daemons.run_proc(process_name, :dir => options[:pid_dir], :dir_mode => :normal, :monitor => @monitor, :ARGV => @args) do |*_args|
Daemons.run_proc(process_name, :dir => options[:pid_dir], :dir_mode => :normal, :monitor => @monitor, :ARGV => @args,:ontop => @options[:ontop] ) do |*_args|
$0 = File.join(options[:prefix], process_name) if @options[:prefix]
run process_name, options
end
Expand Down