Skip to content

Instantly share code, notes, and snippets.

@devdatta
Forked from defunkt/jobs_per_fork.rb
Created April 2, 2010 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdatta/352787 to your computer and use it in GitHub Desktop.
Save devdatta/352787 to your computer and use it in GitHub Desktop.
Resque.after_fork do |job|
# How many jobs should we process in each fork?
jobs_per_fork = [ ENV['JOBS_PER_FORK'].to_i, 1 ].max
# Set hook to nil to prevent running this hook over
# and over while processing more jobs in this fork.
Resque.after_fork = nil
# Make sure we process jobs in the right order.
job.worker.process(job)
# One less than specified because the child will run a
# final job after exiting this hook.
(jobs_per_fork.to_i - 1).times do
job.worker.process
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment