Class: Robinhood::Runtime

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeRuntime

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

Parameters:

  • value

    the value to set the attribute redis to.



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, options, block)
  @processes << [name, options, 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(options = {})
  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

#stopObject

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