class Robinhood::Runtime
A Runtime
is responsible of kickstarting a Robinhood’s execution, spawning all the processes and configuring the environment.
Attributes
redis[RW]
Public Class Methods
new()
click to toggle source
Public: Initializes a Runtime
.
# File lib/robinhood/runtime.rb, line 12 def initialize @processes = [] end
Public Instance Methods
add_process(name, options, block)
click to toggle source
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.
# File lib/robinhood/runtime.rb, line 24 def add_process(name, options, block) @processes << [name, options, block] nil end
run(options = {})
click to toggle source
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
.
# File lib/robinhood/runtime.rb, line 37 def run(options = {}) Celluloid.start setup_supervision_group Mutex.db = redis Robinhood.log :info, "Starting Robin Hood: Robbing from the rich and giving to the poor.." @actor = options[:background] ? supervision_group.run! : supervision_group.run self end
stop()
click to toggle source
Public: Stops this Runtime
.
Returns nil.
# File lib/robinhood/runtime.rb, line 52 def stop @actor.finalize if @actor nil end
Private Instance Methods
setup_supervision_group()
click to toggle source
# File lib/robinhood/runtime.rb, line 67 def setup_supervision_group @processes.each do |process| name, options, block = process supervision_group.supervise Process, as: "robinhood_#{name}", args: [name, options, block] end @processes = [] end
supervision_group()
click to toggle source
# File lib/robinhood/runtime.rb, line 63 def supervision_group @supervision_group ||= Class.new(Celluloid::SupervisionGroup) end