Class: Robinhood::Runtime
- Inherits:
-
Object
- Object
- Robinhood::Runtime
- Defined in:
- lib/robinhood/runtime.rb
Overview
A Runtime is responsible of kickstarting a Robinhood’s execution, spawning all the processes and configuring the environment.
Instance Attribute Summary collapse
-
#redis ⇒ Object
writeonly
Sets the attribute redis.
Instance Method Summary collapse
-
#add_process(name, options, block) ⇒ Object
Public: Schedules a process to be run in this Runtime.
-
#initialize ⇒ Runtime
constructor
Public: Initializes a Runtime.
-
#run(options = {}) ⇒ Object
Public: Starts the Runtime.
-
#stop ⇒ Object
Public: Stops this Runtime.
Constructor Details
#initialize ⇒ Runtime
Public: Initializes a Runtime.
12 13 14 |
# File 'lib/robinhood/runtime.rb', line 12 def initialize @processes = [] end |
Instance Attribute Details
#redis=(value) ⇒ Object
Sets the attribute redis
9 10 11 |
# File 'lib/robinhood/runtime.rb', line 9 def redis=(value) @redis = value end |
Instance Method Details
#add_process(name, options, block) ⇒ Object
Public: Schedules a process to be run in this Runtime.
name - A String identifying this process. options - A Hash of options that will be passed to the underlying
Process.
block - The block that will be evaluated in this Process.
Returns nil.
24 25 26 27 |
# File 'lib/robinhood/runtime.rb', line 24 def add_process(name, , block) @processes << [name, , block] nil end |
#run(options = {}) ⇒ Object
Public: Starts the Runtime.
options - A hash of options to configure this Runtime’s execution.
(default: {background: false})
:background - True if it runs on the background (doesn't block
the main thread), False otherwise.
Returns the Runtime.
37 38 39 40 41 42 43 44 45 |
# File 'lib/robinhood/runtime.rb', line 37 def run( = {}) setup_supervision_group Mutex.db = redis Robinhood.log :info, "Starting Robin Hood: Robbing from the rich and giving to the poor.." @actor = [:background] ? supervision_group.run! : supervision_group.run self end |
#stop ⇒ Object
Public: Stops this Runtime.
Returns nil.
50 51 52 53 |
# File 'lib/robinhood/runtime.rb', line 50 def stop @actor.finalize if @actor nil end |