Class: SayWhen::Store::Memory::Job

Inherits:
Object
  • Object
show all
Includes:
BaseJob, SayWhen::Storage::Memory::Base
Defined in:
lib/say_when/storage/memory/job.rb

Overview

define a trigger class

Constant Summary collapse

@@jobs =
SortedSet.new

Constants included from BaseJob

BaseJob::STATE_ACQUIRED, BaseJob::STATE_COMPLETE, BaseJob::STATE_ERROR, BaseJob::STATE_WAITING

Instance Attribute Summary

Attributes included from SayWhen::Storage::Memory::Base

#props

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseJob

#execute, #execute_job, #fired, #get_task, #load_trigger, #lock, #release, #trigger

Methods included from SayWhen::Storage::Memory::Base

#has_properties, included

Constructor Details

#initialize(options = {}) ⇒ Job

Returns a new instance of Job.



33
34
35
36
37
38
# File 'lib/say_when/storage/memory/job.rb', line 33

def initialize(options={})
  super
  self.status = STATE_WAITING unless self.status
  self.next_fire_at = trigger.next_fire_at
  self.class.jobs << self
end

Class Method Details

.acquire_next(no_later_than) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/say_when/storage/memory/job.rb', line 21

def self.acquire_next(no_later_than)
  self.lock.synchronize {
    
    next_job = jobs.detect(nil) do |j|
      (j.status == STATE_WAITING) && (j.next_fire_at.to_i <= no_later_than.to_i)
    end

    next_job.status = STATE_ACQUIRED if next_job
    next_job
  }          
end

Instance Method Details

#<=>(job) ⇒ Object



40
41
42
# File 'lib/say_when/storage/memory/job.rb', line 40

def <=>(job)
  self.next_fire_at.to_i <=> job.next_fire_at.to_i
end