Skip to content

Instantly share code, notes, and snippets.

@defunkt
Created March 30, 2010 18:11
Show Gist options
  • Select an option

  • Save defunkt/349376 to your computer and use it in GitHub Desktop.

Select an option

Save defunkt/349376 to your computer and use it in GitHub Desktop.
Resque hook to run N jobs per fork
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
@defunkt
Copy link
Author

defunkt commented Nov 14, 2010

I probably wouldn't use this in production, no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment