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 no-wait and force-kill-waittime options to Delayed::Comand #459

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/delayed/command.rb
Expand Up @@ -12,7 +12,8 @@ class Command
def initialize(args)
@options = {
:quiet => true,
:pid_dir => "#{Rails.root}/tmp/pids"
:pid_dir => "#{Rails.root}/tmp/pids",
:force_kill_waittime => 20
}

@worker_count = 1
Expand Down Expand Up @@ -61,6 +62,12 @@ def initialize(args)
opts.on('--queue=queue', "Specify which queue DJ must look up for jobs") do |queue|
@options[:queues] = queue.split(',')
end
opts.on('--no-wait', "Avoid killing the process if a current job is long run") do
@no_wait = true
end
opts.on('--kill-waitime', "Amount of time to wait to kill the process after sending the stop command") do |n|
@options[:force_kill_waittime] = n.to_i
end
end
@args = opts.parse!(args)
end
Expand All @@ -84,7 +91,15 @@ def daemonize

def run_process(process_name, dir)
Delayed::Worker.before_fork
Daemons.run_proc(process_name, :dir => dir, :dir_mode => :normal, :monitor => @monitor, :ARGV => @args) do |*args|

opts = { :dir => dir,
:dir_mode => :normal,
:monitor => @monitor,
:no_wait => @no_wait,
:force_kill_waittime => @options.delete(:force_kill_waittime),
:ARGV => @args }

Daemons.run_proc(process_name, opts) do |*args|
$0 = File.join(@options[:prefix], process_name) if @options[:prefix]
run process_name
end
Expand Down