Skip to content

Instantly share code, notes, and snippets.

@defunkt
Created March 30, 2010 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save defunkt/349376 to your computer and use it in GitHub Desktop.
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
@mguterl
Copy link

mguterl commented Nov 11, 2010

is this still legit? we started using it and we noticed some jobs were being processed multiple times.

I also noticed that Resque::Worker#process is now deprecated

@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