Class: BeanstalkFarmer::Job
- Inherits:
-
Object
- Object
- BeanstalkFarmer::Job
- Defined in:
- lib/beanstalk_farmer/job.rb
Defined Under Namespace
Classes: OutOfTimeError
Instance Attribute Summary (collapse)
-
- (Object) args
Returns the value of attribute args.
-
- (Object) job
Returns the value of attribute job.
-
- (Object) name
Returns the value of attribute name.
Class Method Summary (collapse)
-
+ (Hash) handler_pool(reset = false)
A pool of job handlers that can work on jobs in our queue.
Instance Method Summary (collapse)
-
- (Job) initialize(job)
constructor
A new instance of Job.
-
- (Object) work
Performs work for this job.
Constructor Details
- (Job) initialize(job)
A new instance of Job
13 14 15 16 |
# File 'lib/beanstalk_farmer/job.rb', line 13 def initialize(job) self.job = job set_name_and_arguments end |
Instance Attribute Details
- (Object) args
Returns the value of attribute args
9 10 11 |
# File 'lib/beanstalk_farmer/job.rb', line 9 def args @args end |
- (Object) job
Returns the value of attribute job
9 10 11 |
# File 'lib/beanstalk_farmer/job.rb', line 9 def job @job end |
- (Object) name
Returns the value of attribute name
9 10 11 |
# File 'lib/beanstalk_farmer/job.rb', line 9 def name @name end |
Class Method Details
+ (Hash) handler_pool(reset = false)
A pool of job handlers that can work on jobs in our queue
39 40 41 42 |
# File 'lib/beanstalk_farmer/job.rb', line 39 def self.handler_pool(reset=false) @pool = nil if reset @pool ||= Hash.new end |
Instance Method Details
- (Object) work
Performs work for this job
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/beanstalk_farmer/job.rb', line 19 def work # Stalker, the inspiration for this project, subtracted 1 from the job's # TTR value. I'm not sure why at this point in time. Maybe to compensate # for Job setup time. Timeout.timeout(job.ttr) do handler = self.class.handler_pool[name] handler.call(args) end rescue Timeout::Error raise OutOfTimeError, "#{name} could not finish in #{job.ttr} seconds" ensure job.delete end |