hustle 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hustle/runner.rb +5 -19
- data/lib/hustle/version.rb +1 -1
- data/lib/hustle.rb +16 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0751e2a30bd9eaa27e1a2d91386ac2e708e3dec2
|
4
|
+
data.tar.gz: b398cd8b489a16bfeb07ad6ecae646dac4633d6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49e168a14e448afe2a261672f0493588219bd86fbb0055374a730fa52bc7d22f33f6479598f0ef7d8516ff75506ebd69a7435fdbad26a86527a7a979dc88fd40
|
7
|
+
data.tar.gz: 046f513b6dd4045aa34091c854f9fd9e1b88ee099689b3787f6ecdc32d64e10c372a749a8d533610eb69a0ceae6d03d08d103fc7167fca8a06c066d08a1d8201
|
data/lib/hustle/runner.rb
CHANGED
@@ -41,17 +41,10 @@ module Hustle
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def run_remote(&block)
|
44
|
+
sleep 0 while !remote_instance_ready?
|
44
45
|
remote_instance.run(&block)
|
45
46
|
end
|
46
47
|
|
47
|
-
def remote_instance_finished?
|
48
|
-
remote_instance.finished?
|
49
|
-
end
|
50
|
-
|
51
|
-
def remote_value
|
52
|
-
remote_instance.value
|
53
|
-
end
|
54
|
-
|
55
48
|
# methods to be run on the remote instance
|
56
49
|
|
57
50
|
def stop
|
@@ -59,20 +52,13 @@ module Hustle
|
|
59
52
|
end
|
60
53
|
|
61
54
|
def run
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
@value = e
|
67
|
-
end
|
68
|
-
@finished = true
|
55
|
+
begin
|
56
|
+
yield
|
57
|
+
rescue Exception => e
|
58
|
+
e
|
69
59
|
end
|
70
60
|
end
|
71
61
|
|
72
|
-
def finished?
|
73
|
-
!!@finished
|
74
|
-
end
|
75
|
-
|
76
62
|
end
|
77
63
|
|
78
64
|
end
|
data/lib/hustle/version.rb
CHANGED
data/lib/hustle.rb
CHANGED
@@ -27,7 +27,10 @@ module Hustle
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def start_drb
|
30
|
-
@drb ||=
|
30
|
+
@drb ||= begin
|
31
|
+
DRb.start_service
|
32
|
+
sleep 0 while server.is_a?(DRb::DRbServerNotFound)
|
33
|
+
end
|
31
34
|
end
|
32
35
|
|
33
36
|
def stop_drb
|
@@ -45,12 +48,10 @@ module Hustle
|
|
45
48
|
uri = "druby://127.0.0.1:#{random_port}"
|
46
49
|
runner = Runner.new(uri)
|
47
50
|
runner.start_remote_instance
|
48
|
-
sleep 0 while !runner.remote_instance_ready?
|
49
51
|
synchronize do
|
50
52
|
active_runners[runner.pid] = runner
|
51
53
|
end
|
52
|
-
runner
|
53
|
-
finish runner, callback
|
54
|
+
finish runner, callback, &block
|
54
55
|
end
|
55
56
|
|
56
57
|
def wait
|
@@ -69,19 +70,26 @@ module Hustle
|
|
69
70
|
port
|
70
71
|
end
|
71
72
|
|
72
|
-
def finish(runner, callback)
|
73
|
+
def finish(runner, callback, &block)
|
73
74
|
runner.callback_thread = Thread.new do
|
74
|
-
|
75
|
-
value = runner.remote_value
|
75
|
+
value = runner.run_remote(&block)
|
76
76
|
runner.stop_remote_instance
|
77
|
-
stop_drb
|
78
77
|
synchronize do
|
79
78
|
active_runners.delete(runner.pid)
|
80
79
|
end
|
80
|
+
stop_drb
|
81
81
|
callback.call value
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
def server
|
86
|
+
begin
|
87
|
+
DRb.current_server
|
88
|
+
rescue DRb::DRbServerNotFound => e
|
89
|
+
e
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
85
93
|
end
|
86
94
|
|
87
95
|
end
|