Skip to content

Commit

Permalink
monitor children and re-fork when they exit
Browse files Browse the repository at this point in the history
  • Loading branch information
dgobaud committed Jan 9, 2014
1 parent 365e140 commit a6c79c7
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/delayed/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,34 @@

desc "Start a delayed_job worker."
task :work => :environment_options do
Delayed::Worker.new(@worker_options).start
if @worker_options[:num_processes] == 1
Delayed::Worker.new(@worker_options).start
else
def fork_delayed(worker_index)
puts "starting worker #{worker_index}"

fork do
Delayed::Worker.after_fork
worker = Delayed::Worker.new(@worker_options)
worker.name_prefix = "delayed_job.#{worker_index} "
worker.start
end
end

Delayed::Worker.before_fork
@worker_options[:num_processes].times do |worker_index|
fork_delayed(worker_index)
end

worker_index = @worker_options[:num_processes]

while true do
Process.wait()

fork_delayed(worker_index)
worker_index = worker_index + 1
end
end
end

desc "Start a delayed_job worker and exit when all available jobs are complete."
Expand Down

0 comments on commit a6c79c7

Please sign in to comment.