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

Support forking of workers (rake jobs:work NUM_PROCESSES=3) #565

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 16 additions & 2 deletions lib/delayed/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@

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
Delayed::Worker.before_fork
@worker_options[:num_processes].times do |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
sleep
end
end

desc "Start a delayed_job worker and exit when all available jobs are complete."
Expand All @@ -19,7 +32,8 @@
:min_priority => ENV['MIN_PRIORITY'],
:max_priority => ENV['MAX_PRIORITY'],
:queues => (ENV['QUEUES'] || ENV['QUEUE'] || '').split(','),
:quiet => false
:quiet => false,
:num_processes => ENV['NUM_PROCESSES'] ? ENV['NUM_PROCESSES'].to_i : 1
}
end

Expand Down