Class: Hustle::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/hustle/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Runner

methods to be run on the local instance



8
9
10
# File 'lib/hustle/runner.rb', line 8

def initialize(uri)
  @uri = uri
end

Instance Attribute Details

#callback_threadObject

Returns the value of attribute callback_thread.



4
5
6
# File 'lib/hustle/runner.rb', line 4

def callback_thread
  @callback_thread
end

#pidObject (readonly)

Returns the value of attribute pid.



3
4
5
# File 'lib/hustle/runner.rb', line 3

def pid
  @pid
end

#uriObject (readonly)

Returns the value of attribute uri.



3
4
5
# File 'lib/hustle/runner.rb', line 3

def uri
  @uri
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/hustle/runner.rb', line 3

def value
  @value
end

Instance Method Details

#remote_instanceObject



12
13
14
# File 'lib/hustle/runner.rb', line 12

def remote_instance
  DRbObject.new_with_uri(uri)
end

#remote_instance_ready?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/hustle/runner.rb', line 20

def remote_instance_ready?
  begin
    !remote_instance.uri.nil?
  rescue DRb::DRbConnError
    false
  end
end

#remote_instance_started?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/hustle/runner.rb', line 16

def remote_instance_started?
  !pid.nil?
end

#runObject



53
54
55
56
57
58
59
# File 'lib/hustle/runner.rb', line 53

def run
  begin
    yield
  rescue Exception => e
    e
  end
end

#run_remote(&block) ⇒ Object



42
43
44
45
# File 'lib/hustle/runner.rb', line 42

def run_remote(&block)
  sleep 0 while !remote_instance_ready?
  remote_instance.run(&block)
end

#start_remote_instanceObject



28
29
30
31
32
33
34
35
36
# File 'lib/hustle/runner.rb', line 28

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

#stopObject

methods to be run on the remote instance



49
50
51
# File 'lib/hustle/runner.rb', line 49

def stop
  DRb.stop_service
end

#stop_remote_instanceObject



38
39
40
# File 'lib/hustle/runner.rb', line 38

def stop_remote_instance
  remote_instance.stop
end