Sha256: ea65f54cb29f0b6dc9bc5822e57fcfa4981462477215e13624ac7c81ef6300d6

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

require 'say_when/storage/memory/base'

module SayWhen
  module Store
    module Memory

      # define a trigger class
      class Job

        cattr_accessor :jobs
        @@jobs = SortedSet.new

        include SayWhen::Storage::Memory::Base
      	include SayWhen::BaseJob

        has_properties :group, :name, :status, :start_at, :end_at
        has_properties :trigger_strategy, :trigger_options, :last_fire_at, :next_fire_at
        has_properties :job_class, :job_method, :data
        has_properties :scheduled

        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

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

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

      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
say_when-0.2.6 lib/say_when/storage/memory/job.rb
say_when-0.2.5 lib/say_when/storage/memory/job.rb
say_when-0.2.4 lib/say_when/storage/memory/job.rb
say_when-0.2.3 lib/say_when/storage/memory/job.rb
say_when-0.2.1 lib/say_when/storage/memory/job.rb
say_when-0.2.0 lib/say_when/storage/memory/job.rb