Created
March 30, 2010 18:11
-
-
Save defunkt/349376 to your computer and use it in GitHub Desktop.
Resque hook to run N jobs per fork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
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