hustle 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hustle/hustler.rb +2 -2
- data/lib/hustle/runner.rb +16 -8
- data/lib/hustle/version.rb +1 -1
- data/test/hustle_test.rb +18 -0
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f677c8b9125928a97fca3ecdf0503266168a650f
|
4
|
+
data.tar.gz: feae1ecf4c817842635ac2e57e7d5b413f6f36c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03dfd4dff8b71fbe0f5f994d1dfd5151cdc1e3b580e235333a094b9f819721a44d8359932bd8b8412bc2e55c2ded6718f23aad93ee1c5b0df206cb68874e84aa
|
7
|
+
data.tar.gz: e0a093a91ef31efec092255916e4d846d98c69a89d194dedec436e9708744fe6e083f9035cc565167775bda2b9660dffe07d7007a14230a20ed2a1d6129adeb9
|
data/lib/hustle/hustler.rb
CHANGED
@@ -33,11 +33,11 @@ module Hustle
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def go(callback: -> (val) {}, &block)
|
36
|
+
def go(context: {}, callback: -> (val) {}, &block)
|
37
37
|
start_drb
|
38
38
|
sleep 0 while active_runners.size >= cores.size
|
39
39
|
uri = "druby://127.0.0.1:#{random_port}"
|
40
|
-
runner = Runner.new(uri)
|
40
|
+
runner = Runner.new(uri, context: context)
|
41
41
|
runner.start_remote_instance
|
42
42
|
synchronize do
|
43
43
|
active_runners[runner.pid] = runner
|
data/lib/hustle/runner.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
require "
|
1
|
+
require "method_source"
|
2
2
|
|
3
3
|
module Hustle
|
4
4
|
class Runner
|
5
|
-
attr_reader :uri, :pid, :
|
5
|
+
attr_reader :uri, :pid, :context
|
6
6
|
attr_accessor :callback_thread
|
7
7
|
|
8
8
|
# methods to be run on the local instance
|
9
9
|
|
10
|
-
def initialize(uri)
|
10
|
+
def initialize(uri, context: {})
|
11
11
|
@uri = uri
|
12
|
+
@context = context
|
12
13
|
end
|
13
14
|
|
14
15
|
def remote_instance
|
@@ -41,10 +42,17 @@ module Hustle
|
|
41
42
|
remote_instance.stop
|
42
43
|
end
|
43
44
|
|
44
|
-
def run_remote(&block)
|
45
|
+
def run_remote(context: {}, &block)
|
45
46
|
sleep 0 while !remote_instance_ready?
|
46
|
-
|
47
|
-
remote_instance.run
|
47
|
+
code_string = proc_to_string(block)
|
48
|
+
remote_instance.run code_string
|
49
|
+
end
|
50
|
+
|
51
|
+
def proc_to_string(proc)
|
52
|
+
code = proc.source
|
53
|
+
start = code.index(/(?<=\{| do)/)
|
54
|
+
finish = code.rindex(/\}|end/) - 1
|
55
|
+
code[start..finish].strip
|
48
56
|
end
|
49
57
|
|
50
58
|
# methods to be run on the remote instance
|
@@ -53,9 +61,9 @@ module Hustle
|
|
53
61
|
DRb.stop_service
|
54
62
|
end
|
55
63
|
|
56
|
-
def run(
|
64
|
+
def run(code_string)
|
57
65
|
begin
|
58
|
-
eval
|
66
|
+
eval code_string, binding
|
59
67
|
rescue Exception => e
|
60
68
|
e
|
61
69
|
end
|
data/lib/hustle/version.rb
CHANGED
data/test/hustle_test.rb
CHANGED
@@ -54,5 +54,23 @@ class HustleTest < MicroTest::Test
|
|
54
54
|
Hustle.wait
|
55
55
|
end
|
56
56
|
|
57
|
+
test "context passing" do
|
58
|
+
data = { a: 0, b: 1 }
|
59
|
+
|
60
|
+
asserts = -> (value) do
|
61
|
+
assert value.is_a?(Hash)
|
62
|
+
assert value[:a] == 0
|
63
|
+
assert value[:b] == 3
|
64
|
+
assert data.object_id != value.object_id
|
65
|
+
end
|
66
|
+
|
67
|
+
Hustle.go context: data, callback: asserts do
|
68
|
+
context[:b] = 3
|
69
|
+
context
|
70
|
+
end
|
71
|
+
|
72
|
+
Hustle.wait
|
73
|
+
end
|
74
|
+
|
57
75
|
end
|
58
76
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hustle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: os
|
@@ -25,33 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.9.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: method_source
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.8.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: sourcify
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.5.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.5.0
|
40
|
+
version: 0.8.2
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|