Module: HireFire::Environment::DelayedJob::ClassMethods

Defined in:
lib/hirefire/environment.rb

Instance Method Summary collapse

Instance Method Details

#hirefire_hirenil

This method is an attempt to improve web-request throughput.

A class method for Delayed::Job which first checks if any worker is currently running by checking to see if there are any jobs locked by a worker. If there aren’t any jobs locked by a worker there is a high chance that there aren’t any workers running. If this is the case, then we sure also invoke the ‘self.class.environment.hire’ method

Another check is to see if there is only 1 job (which is the one that was just added before this callback invoked). If this is the case then it’s very likely there aren’t any workers running and we should invoke the ‘self.class.environment.hire’ method to make sure this is the case.

Returns:

  • (nil)


92
93
94
95
96
97
98
# File 'lib/hirefire/environment.rb', line 92

def hirefire_hire
  delayed_job = ::Delayed::Job.new
  if delayed_job.workers == 0 \
  or delayed_job.jobs    == 1
    environment.hire
  end
end