Class: Resque::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/resque-jobs-per-fork.rb

Instance Method Summary collapse

Instance Method Details

#perform_with_jobs_per_fork(job) ⇒ Object Also known as: perform



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/resque-jobs-per-fork.rb', line 37

def perform_with_jobs_per_fork(job)
  raise "You need to set JOBS_PER_FORK on the command line" unless ENV['JOBS_PER_FORK']
  run_hook :before_perform_jobs_per_fork, self
  jobs_performed ||= 0
  while jobs_performed < ENV['JOBS_PER_FORK'].to_i do
    break if @shutdown
    if jobs_performed == 0
      perform_without_jobs_per_fork(job)
    elsif another_job = reserve
      perform_without_jobs_per_fork(another_job)
    end
    jobs_performed += 1
  end
  jobs_performed = nil
  run_hook :after_perform_jobs_per_fork, self
end