Class: Hustle::Runner
- Inherits:
-
Object
- Object
- Hustle::Runner
- Defined in:
- lib/hustle/runner.rb
Instance Attribute Summary collapse
-
#callback_thread ⇒ Object
Returns the value of attribute callback_thread.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(uri) ⇒ Runner
constructor
methods to be run on the local instance.
- #remote_instance ⇒ Object
- #remote_instance_ready? ⇒ Boolean
- #remote_instance_started? ⇒ Boolean
- #run(source) ⇒ Object
- #run_remote(&block) ⇒ Object
- #start_remote_instance ⇒ Object
-
#stop ⇒ Object
methods to be run on the remote instance.
- #stop_remote_instance ⇒ Object
Constructor Details
#initialize(uri) ⇒ Runner
methods to be run on the local instance
10 11 12 |
# File 'lib/hustle/runner.rb', line 10 def initialize(uri) @uri = uri end |
Instance Attribute Details
#callback_thread ⇒ Object
Returns the value of attribute callback_thread.
6 7 8 |
# File 'lib/hustle/runner.rb', line 6 def callback_thread @callback_thread end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
5 6 7 |
# File 'lib/hustle/runner.rb', line 5 def pid @pid end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
5 6 7 |
# File 'lib/hustle/runner.rb', line 5 def uri @uri end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/hustle/runner.rb', line 5 def value @value end |
Instance Method Details
#remote_instance ⇒ Object
14 15 16 |
# File 'lib/hustle/runner.rb', line 14 def remote_instance DRbObject.new_with_uri(uri) end |
#remote_instance_ready? ⇒ Boolean
22 23 24 25 26 27 28 |
# File 'lib/hustle/runner.rb', line 22 def remote_instance_ready? begin !remote_instance.uri.nil? rescue DRb::DRbConnError false end end |
#remote_instance_started? ⇒ Boolean
18 19 20 |
# File 'lib/hustle/runner.rb', line 18 def remote_instance_started? !pid.nil? end |
#run(source) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/hustle/runner.rb', line 56 def run(source) begin eval source rescue Exception => e e end end |
#run_remote(&block) ⇒ Object
44 45 46 47 48 |
# File 'lib/hustle/runner.rb', line 44 def run_remote(&block) sleep 0 while !remote_instance_ready? source = block.to_source(strip_enclosure: true) remote_instance.run source end |
#start_remote_instance ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/hustle/runner.rb', line 30 def start_remote_instance return if remote_instance_started? @pid = fork do DRb.start_service uri, self DRb.thread.join end Process.detach pid pid end |
#stop ⇒ Object
methods to be run on the remote instance
52 53 54 |
# File 'lib/hustle/runner.rb', line 52 def stop DRb.stop_service end |
#stop_remote_instance ⇒ Object
40 41 42 |
# File 'lib/hustle/runner.rb', line 40 def stop_remote_instance remote_instance.stop end |