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



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

def initialize(uri)
  @uri = uri
end

Instance Attribute Details

#callback_threadObject

Returns the value of attribute callback_thread.



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

def callback_thread
  @callback_thread
end

#pidObject (readonly)

Returns the value of attribute pid.



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

def pid
  @pid
end

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/hustle/runner.rb', line 72

def finished?
  !!@finished
end

#remote_instanceObject



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

def remote_instance
  DRbObject.new_with_uri(uri)
end

#remote_instance_finished?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/hustle/runner.rb', line 47

def remote_instance_finished?
  remote_instance.finished?
end

#remote_instance_ready?Boolean

Returns:

  • (Boolean)


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

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

#remote_instance_started?Boolean

Returns:

  • (Boolean)


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

def remote_instance_started?
  !pid.nil?
end

#remote_valueObject



51
52
53
# File 'lib/hustle/runner.rb', line 51

def remote_value
  remote_instance.value
end

#runObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/hustle/runner.rb', line 61

def run
  Thread.new do
    begin
      @value = yield
    rescue Exception => e
      @value = e
    end
    @finished = true
  end
end

#run_remote(&block) ⇒ Object



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

def run_remote(&block)
  remote_instance.run(&block)
end

#start_remote_instanceObject



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

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



57
58
59
# File 'lib/hustle/runner.rb', line 57

def stop
  DRb.stop_service
end

#stop_remote_instanceObject



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

def stop_remote_instance
  remote_instance.stop
end