Class: Allora::Job
- Inherits:
-
Object
- Object
- Allora::Job
- Defined in:
- lib/allora/job.rb
Overview
Abstract job class providing a wrapper around job execution.
Subclasses must be able to provide a time for the job to run, given a start time.
Defined Under Namespace
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Instance Method Summary collapse
-
#execute ⇒ Object
Execute the job.
-
#initialize(&block) ⇒ Job
constructor
Initialize the job with the given block to invoke during execution.
-
#next_at(from_time) ⇒ Time
Returns the next time at which this job should run.
Constructor Details
#initialize(&block) ⇒ Job
Initialize the job with the given block to invoke during execution.
33 34 35 |
# File 'lib/allora/job.rb', line 33 def initialize(&block) @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
30 31 32 |
# File 'lib/allora/job.rb', line 30 def block @block end |
Instance Method Details
#execute ⇒ Object
Execute the job.
Execution happens inside a forked and detached child.
40 41 42 |
# File 'lib/allora/job.rb', line 40 def execute Process.detach(fork { @block.call }) end |
#next_at(from_time) ⇒ Time
Returns the next time at which this job should run.
Subclasses must implement this method.
53 54 55 |
# File 'lib/allora/job.rb', line 53 def next_at(from_time) raise NotImplementedError, "Abstract method #next_at must be overridden by subclasses" end |