iron_response 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/iron_response/batch.rb +13 -23
- data/lib/iron_response/common.rb +9 -0
- data/lib/iron_response/error.rb +11 -0
- data/lib/iron_response/version.rb +1 -1
- data/lib/iron_response.rb +1 -0
- data/test/gem_dependency_test.rb +21 -18
- data/test/synopsis_test.rb +19 -13
- metadata +2 -1
data/lib/iron_response/batch.rb
CHANGED
@@ -8,12 +8,11 @@ module IronResponse
|
|
8
8
|
attr_accessor :config
|
9
9
|
attr_accessor :worker
|
10
10
|
attr_accessor :params_array
|
11
|
-
attr_accessor :auto_update_worker
|
12
11
|
attr_accessor :results
|
13
12
|
|
14
|
-
def initialize
|
15
|
-
@
|
16
|
-
@
|
13
|
+
def initialize(config)
|
14
|
+
@config = config
|
15
|
+
@client = IronWorkerNG::Client.new(@config[:iron_io])
|
17
16
|
end
|
18
17
|
|
19
18
|
def worker_name
|
@@ -21,22 +20,14 @@ module IronResponse
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def run!
|
24
|
-
@client = IronWorkerNG::Client.new(@config[:iron_io])
|
25
|
-
|
26
|
-
if @auto_update_worker
|
27
|
-
create_code!
|
28
|
-
end
|
29
|
-
|
30
23
|
task_ids = params_array.map do |params|
|
31
24
|
params[:config] = @config
|
32
25
|
@client.tasks.create(worker_name, params)._id
|
33
26
|
end
|
34
27
|
|
35
|
-
task_ids.
|
36
|
-
|
28
|
+
task_ids.map do |task_id|
|
29
|
+
get_response_from_task_id(@client.tasks.wait_for(task_id)._id)
|
37
30
|
end
|
38
|
-
|
39
|
-
@results
|
40
31
|
end
|
41
32
|
|
42
33
|
def get_response_from_task_id(task_id)
|
@@ -56,20 +47,20 @@ module IronResponse
|
|
56
47
|
bucket_name = IronResponse::Common.s3_bucket_name(@config)
|
57
48
|
bucket = AWS::S3::Bucket.find(bucket_name)
|
58
49
|
path = IronResponse::Common.s3_path(task_id)
|
59
|
-
response = bucket[path]
|
50
|
+
response = bucket[path]
|
60
51
|
|
61
|
-
|
52
|
+
IronResponse::Common.handle_response(response, task_id, @client)
|
62
53
|
end
|
63
54
|
|
64
55
|
def get_iron_cache_response(task_id)
|
65
56
|
cache_client = IronCache::Client.new(@config[:iron_io])
|
66
57
|
cache_name = IronResponse::Common.iron_cache_cache_name(@config)
|
67
58
|
cache = cache_client.cache(cache_name)
|
59
|
+
|
60
|
+
key = IronResponse::Common.iron_cache_key(task_id)
|
61
|
+
response = cache.get(key)
|
68
62
|
|
69
|
-
|
70
|
-
value = cache.get(key).value
|
71
|
-
|
72
|
-
JSON.parse(value)
|
63
|
+
IronResponse::Common.handle_response(response, task_id, @client)
|
73
64
|
end
|
74
65
|
|
75
66
|
def code
|
@@ -87,9 +78,8 @@ module IronResponse
|
|
87
78
|
@client.codes.patch(code)
|
88
79
|
end
|
89
80
|
|
90
|
-
def create_code!
|
91
|
-
@client.codes.create(code)
|
81
|
+
def create_code!(options={})
|
82
|
+
@client.codes.create(code, options)
|
92
83
|
end
|
93
84
|
end
|
94
|
-
|
95
85
|
end
|
data/lib/iron_response/common.rb
CHANGED
@@ -24,5 +24,14 @@ module IronResponse
|
|
24
24
|
def Common.response_provider(config)
|
25
25
|
config[:aws_s3].nil? ? :iron_cache : :aws_s3
|
26
26
|
end
|
27
|
+
|
28
|
+
def Common.handle_response(response, task_id, client)
|
29
|
+
if response.nil?
|
30
|
+
msg = client.tasks_log(task_id)
|
31
|
+
IronResponse::Error.new("IronWorker error: #{msg}")
|
32
|
+
else
|
33
|
+
JSON.parse(response.value)
|
34
|
+
end
|
35
|
+
end
|
27
36
|
end
|
28
37
|
end
|
data/lib/iron_response.rb
CHANGED
data/test/gem_dependency_test.rb
CHANGED
@@ -4,15 +4,9 @@ class GemDependencyTest < MiniTest::Unit::TestCase
|
|
4
4
|
def test_synopsis_with_iron_cache
|
5
5
|
|
6
6
|
config = Configuration.keys
|
7
|
-
batch = IronResponse::Batch.new
|
7
|
+
batch = IronResponse::Batch.new(iron_io: config[:iron_io])
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
batch.config[:iron_io] = config[:iron_io]
|
12
|
-
|
13
|
-
#batch.config[:iron_io] = config[:iron_io]
|
14
|
-
#batch.config[:aws_s3] = config[:aws_s3]
|
15
|
-
batch.worker = "test/workers/fcc_filings_counter.rb"
|
9
|
+
batch.worker = "test/workers/fcc_filings_counter.rb"
|
16
10
|
|
17
11
|
batch.code.merge_gem("nokogiri", "< 1.6.0") # keeps the build times low
|
18
12
|
batch.code.merge_gem("ecfs")
|
@@ -24,26 +18,29 @@ class GemDependencyTest < MiniTest::Unit::TestCase
|
|
24
18
|
"13-150", "13-5",
|
25
19
|
"10-71"
|
26
20
|
].map { |i| {docket_number: i} }
|
27
|
-
|
21
|
+
batch.create_code!
|
22
|
+
|
28
23
|
results = batch.run!
|
29
24
|
|
25
|
+
binding.pry
|
26
|
+
|
27
|
+
assert_equal batch.params_array.length, results.length
|
28
|
+
|
29
|
+
results.select! {|r| !r.is_a?(IronResponse::Error)}
|
30
|
+
|
30
31
|
total = results.map {|r| r["length"]}.inject(:+)
|
31
32
|
|
32
33
|
p "There are #{total} total filings in these dockets."
|
33
34
|
|
34
35
|
assert_equal Array, results.class
|
35
|
-
assert_equal batch.params_array.length, results.length
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_synopsis_with_aws_s3
|
39
39
|
|
40
40
|
config = Configuration.keys
|
41
|
-
batch = IronResponse::Batch.new
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
batch.config = config
|
46
|
-
batch.worker = "test/workers/fcc_filings_counter.rb"
|
41
|
+
batch = IronResponse::Batch.new(config)
|
42
|
+
|
43
|
+
batch.worker = "test/workers/fcc_filings_counter.rb"
|
47
44
|
|
48
45
|
batch.code.merge_gem("nokogiri", "< 1.6.0") # keeps the build times low
|
49
46
|
batch.code.merge_gem("ecfs")
|
@@ -56,14 +53,20 @@ class GemDependencyTest < MiniTest::Unit::TestCase
|
|
56
53
|
"10-71"
|
57
54
|
].map { |i| {docket_number: i} }
|
58
55
|
|
59
|
-
|
56
|
+
batch.create_code!
|
57
|
+
results = batch.run!
|
58
|
+
|
59
|
+
assert_equal batch.params_array.length, results.length
|
60
|
+
|
61
|
+
binding.pry
|
62
|
+
|
63
|
+
results.select! {|r| !r.is_a?(IronResponse::Error)}
|
60
64
|
|
61
65
|
total = results.map {|r| r["length"]}.inject(:+)
|
62
66
|
|
63
67
|
p "There are #{total} total filings in these dockets."
|
64
68
|
|
65
69
|
assert_equal Array, results.class
|
66
|
-
assert_equal batch.params_array.length, results.length
|
67
70
|
end
|
68
71
|
|
69
72
|
end
|
data/test/synopsis_test.rb
CHANGED
@@ -3,34 +3,40 @@ require "test_helper"
|
|
3
3
|
class SynopsisTest < MiniTest::Unit::TestCase
|
4
4
|
def test_synopsis_with_s3
|
5
5
|
config = Configuration.keys
|
6
|
-
batch = IronResponse::Batch.new
|
6
|
+
batch = IronResponse::Batch.new(config)
|
7
7
|
|
8
|
-
batch.auto_update_worker = true
|
9
|
-
batch.config[:iron_io] = config[:iron_io]
|
10
|
-
batch.config[:aws_s3] = config[:aws_s3]
|
11
8
|
batch.worker = "test/workers/hello.rb"
|
12
9
|
batch.params_array = Array(1..4).map {|i| {number: i}}
|
10
|
+
batch.create_code!
|
11
|
+
|
12
|
+
results = batch.run!
|
13
|
+
|
14
|
+
assert_equal batch.params_array.length, results.length
|
15
|
+
|
16
|
+
results.select! {|r| !r.is_a?(IronResponse::Error)}
|
13
17
|
|
14
|
-
|
18
|
+
binding.pry
|
15
19
|
|
16
20
|
assert_equal Array, results.class
|
17
|
-
assert_equal batch.params_array.length, results.length
|
18
|
-
assert_equal true, results.select {|r| r.nil?}.length == 0
|
19
21
|
end
|
20
22
|
|
21
23
|
def test_synopsis_with_iron_cache
|
22
24
|
config = Configuration.keys
|
23
|
-
batch = IronResponse::Batch.new
|
25
|
+
batch = IronResponse::Batch.new(iron_io: config[:iron_io])
|
24
26
|
|
25
|
-
batch.auto_update_worker = true
|
26
|
-
batch.config[:iron_io] = config[:iron_io]
|
27
27
|
batch.worker = "test/workers/hello.rb"
|
28
28
|
batch.params_array = Array(1..4).map {|i| {number: i}}
|
29
29
|
|
30
|
-
|
30
|
+
batch.create_code!
|
31
|
+
|
32
|
+
results = batch.run!
|
31
33
|
|
32
|
-
assert_equal Array, results.class
|
33
34
|
assert_equal batch.params_array.length, results.length
|
34
|
-
|
35
|
+
|
36
|
+
results.select! {|r| !r.is_a?(IronResponse::Error)}
|
37
|
+
|
38
|
+
binding.pry
|
39
|
+
|
40
|
+
assert_equal Array, results.class
|
35
41
|
end
|
36
42
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron_response
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/iron_response.rb
|
124
124
|
- lib/iron_response/batch.rb
|
125
125
|
- lib/iron_response/common.rb
|
126
|
+
- lib/iron_response/error.rb
|
126
127
|
- lib/iron_response/version.rb
|
127
128
|
- lib/iron_response/worker.rb
|
128
129
|
- test/configuration.rb.example
|