Sha256: f05e5e18d47bfed0346864b51bb53ef5d46cc90acc6e81c1756381b29f38ca74

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

require 'nestene/delayed_method'
require 'securerandom'
require 'structure_mapper'

module Nestene
  class AutonExecutionQueue
    include StructureMapper::Hash

    def initialize
      self.to_execute = []
      self.executed = []
      self.delayed = []
    end

    def add_delayed_method name, parameters, delay, every = nil
      delayed_method = DelayedMethod.new
      delayed_method.uuid = SecureRandom.uuid
      delayed_method.name = name
      delayed_method.parameters = parameters
      delayed_method.execute_at = Time.now + delay
      delayed_method.every = every
      add_delayed(delayed_method)
      delayed_method
    end

    def add_delayed delayed_method
      delayed << delayed_method
      delayed.sort_by! {|x| x.execute_at}
    end


    def remove_delayed_method method_uuid
      delayed.delete_if{|m| m.uuid == method_uuid}
    end

    attribute failed: Boolean
    attribute to_execute: [ScheduledMethod]
    attribute executed: [ExecutedMethod]
    attribute currently_executing: ExecutingMethod
    attribute delayed: [DelayedMethod]

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nestene-0.1.8 lib/nestene/auton_execution_queue.rb
nestene-0.1.7 lib/nestene/auton_execution_queue.rb
nestene-0.1.6 lib/nestene/auton_execution_queue.rb
nestene-0.1.5 lib/nestene/auton_execution_queue.rb
nestene-0.1.4 lib/nestene/auton_execution_queue.rb
nestene-0.1.3 lib/nestene/auton_execution_queue.rb
nestene-0.1.2 lib/nestene/auton_execution_queue.rb
nestene-0.1.1 lib/nestene/auton_execution_queue.rb
nestene-0.1.0 lib/nestene/auton_execution_queue.rb