Class: Nestene::AutonExecutionQueue
- Inherits:
-
Object
- Object
- Nestene::AutonExecutionQueue
- Includes:
- StructureMapper::Hash
- Defined in:
- lib/nestene/auton_execution_queue.rb
Instance Method Summary collapse
- #add_delayed(delayed_method) ⇒ Object
- #add_delayed_method(name, parameters, delay, every = nil) ⇒ Object
- #add_executed(executed) ⇒ Object
-
#initialize ⇒ AutonExecutionQueue
constructor
A new instance of AutonExecutionQueue.
- #remove_delayed_method(method_uuid) ⇒ Object
Constructor Details
#initialize ⇒ AutonExecutionQueue
Returns a new instance of AutonExecutionQueue.
9 10 11 12 13 |
# File 'lib/nestene/auton_execution_queue.rb', line 9 def initialize self.to_execute = [] self.executed = [] self.delayed = [] end |
Instance Method Details
#add_delayed(delayed_method) ⇒ Object
26 27 28 29 |
# File 'lib/nestene/auton_execution_queue.rb', line 26 def add_delayed delayed_method delayed << delayed_method delayed.sort_by! {|x| x.execute_at} end |
#add_delayed_method(name, parameters, delay, every = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nestene/auton_execution_queue.rb', line 15 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 |
#add_executed(executed) ⇒ Object
31 32 33 34 |
# File 'lib/nestene/auton_execution_queue.rb', line 31 def add_executed executed self.executed.shift while self.executed.size >= 20 self.executed << executed end |
#remove_delayed_method(method_uuid) ⇒ Object
37 38 39 |
# File 'lib/nestene/auton_execution_queue.rb', line 37 def remove_delayed_method method_uuid delayed.delete_if{|m| m.uuid == method_uuid} end |