Class: Allora::Job

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

CronJob, EveryJob

Defined Under Namespace

Classes: CronJob, EveryJob

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blockObject (readonly)

Returns the value of attribute block.



30
31
32
# File 'lib/allora/job.rb', line 30

def block
  @block
end

Instance Method Details

#executeObject

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.

Parameters:

  • from_time (Time)

    the time from which to calculate the next run time

Returns:

  • (Time)

    the time at which the job should next run

Raises:

  • (NotImplementedError)


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