Module: Scheduler

Defined in:
lib/ara/scheduler.rb

Defined Under Namespace

Classes: Action, Actions

Constant Summary collapse

SECOND =
1
MINUTE =
60 * SECOND
HOUR =
60 * MINUTE
DAY =
25 * HOUR
WEEK =
7 * DAY
MONTH =
(365 * DAY) / 12
YEAR =
365 * DAY

Class Method Summary collapse

Class Method Details

.actionsObject

Return all actions



52
53
54
# File 'lib/ara/scheduler.rb', line 52

def self.actions
   Scheduler::Actions.instance
end

.pauseObject

Pause all scheduled actions



47
48
49
# File 'lib/ara/scheduler.rb', line 47

def self.pause
   actions.each { |a| a.pause }
end

.restartObject

Restart all scheduled actions



37
38
39
# File 'lib/ara/scheduler.rb', line 37

def self.restart
   actions.each { |a| a.rstart }
end

.schedule(receiver_actor, message, initial_delay_before_send, delay_between_messages, time_unit) {|action| ... } ⇒ Object

Create a scheduler to send the message message to actor receiver_actor every delay_between_messages time_unit with an initial delay of initial_delay_before_send time_unit

Yields:

  • (action)


14
15
16
17
18
19
20
# File 'lib/ara/scheduler.rb', line 14

def self.schedule(receiver_actor, message, initial_delay_before_send, delay_between_messages, time_unit) 
   action = Action.new(receiver_actor, message, initial_delay_before_send, delay_between_messages, time_unit)
   actions.add(action)
   action.start
   yield action if block_given?
   action
end

.schedule_once(receiver_actor, message, delay_until_send, time_unit) {|action| ... } ⇒ Object

Create a scheduler to send the message message to actor receiver_actor after delay_until_send time_unit

Yields:

  • (action)


23
24
25
26
27
28
29
# File 'lib/ara/scheduler.rb', line 23

def self.schedule_once(receiver_actor, message, delay_until_send, time_unit)
   action = Action.new(receiver_actor, message, delay_until_send, nil, time_unit)
   actions.add(action)
   action.start
   yield action if block_given?
   action
end

.shutdownObject

Shutdown all scheduled actions



32
33
34
# File 'lib/ara/scheduler.rb', line 32

def self.shutdown
   actions.each { |a| a.shutdown }
end

.stopObject

Stop all scheduled actions



42
43
44
# File 'lib/ara/scheduler.rb', line 42

def self.stop
   actions.each { |a| a.stop }
end