iron_response 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/iron_response.rb CHANGED
@@ -2,7 +2,7 @@ require "iron_response/version"
2
2
  require "iron_response/common"
3
3
  require "iron_response/batch"
4
4
  require "iron_response/worker"
5
- require "iron_response/error"
5
+ require "iron_response/log"
6
6
 
7
7
  module IronResponse
8
8
  end
@@ -6,9 +6,10 @@ require "json"
6
6
  module IronResponse
7
7
  class Batch
8
8
  attr_accessor :config
9
- attr_accessor :worker
9
+ attr_accessor :name
10
10
  attr_accessor :params_array
11
11
  attr_accessor :results
12
+ attr_accessor :code
12
13
 
13
14
  def initialize(config)
14
15
  @config = config
@@ -16,11 +17,7 @@ module IronResponse
16
17
  end
17
18
 
18
19
  def worker_name
19
- @worker.split("/").last.split(".rb").first
20
- end
21
-
22
- def worker_language
23
- is_ruby
20
+ @code.name
24
21
  end
25
22
 
26
23
  def run!
@@ -68,44 +65,13 @@ module IronResponse
68
65
  IronResponse::Common.handle_response(response, task_id, @client)
69
66
  end
70
67
 
71
- def runtime
72
- return "ruby" if @worker.end_with?(".rb")
73
- return "node" if @worker.end_with?(".js")
74
- end
75
-
76
- def prepare_ruby_code(code)
77
- code.runtime = "ruby"
78
- end
79
-
80
- def prepare_node_code(code)
81
- code.runtime = "node"
82
- code.dir = "node_modules"
83
- code.file = "package.json"
84
- end
85
-
86
- def code
87
- if @code.nil?
88
- @code = IronWorkerNG::Code::Ruby.new(exec: @worker)
89
- @code.name = worker_name
90
- @code.merge_gem("iron_response", IronResponse::VERSION) # bootstraps the current version with the worker
91
-
92
- case runtime
93
- when "ruby"
94
- prepare_ruby_code(@code)
95
- when "node"
96
- prepare_node_code(@code)
97
- end
98
- end
99
-
100
- @code
101
- end
102
-
103
- def patch_code!
104
- @client.codes.patch(code)
68
+ def patch_code!(options={})
69
+ @client.codes.patch(@code, options)
105
70
  end
106
71
 
107
72
  def create_code!(options={})
108
- @client.codes.create(code, options)
73
+ @code.merge_gem("iron_response", IronResponse::VERSION) if @code.runtime == "ruby" # bootstraps the current version with the worker
74
+ @client.codes.create(@code, options)
109
75
  end
110
76
  end
111
77
  end
@@ -27,8 +27,9 @@ module IronResponse
27
27
 
28
28
  def Common.handle_response(response, task_id, client)
29
29
  if response.nil?
30
+ p "getting error for Task ID: #{task_id}"
30
31
  msg = client.tasks_log(task_id)
31
- IronResponse::Error.new("IronWorker error: #{msg}")
32
+ IronResponse::Log.new("IronWorker logs for task #{task_id}: #{msg}")
32
33
  else
33
34
  JSON.parse(response.value)
34
35
  end
@@ -1,5 +1,5 @@
1
1
  module IronResponse
2
- class Error
2
+ class Log
3
3
  def initialize(text)
4
4
  @text = text
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module IronResponse
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -6,32 +6,31 @@ class GemDependencyTest < MiniTest::Unit::TestCase
6
6
  config = Configuration.keys
7
7
  batch = IronResponse::Batch.new(iron_io: config[:iron_io])
8
8
 
9
- batch.worker = "test/workers/fcc_filings_counter.rb"
10
-
11
- batch.code.merge_gem("nokogiri", "< 1.6.0") # keeps the build times low
12
- batch.code.merge_gem("ecfs")
13
- batch.code.full_remote_build(true)
14
-
15
- batch.params_array = [
16
- "12-375", "12-268",
17
- "12-238", "12-353",
18
- "13-150", "13-5",
19
- "10-71"
20
- ].map { |i| {docket_number: i} }
9
+ code = IronWorkerNG::Code::Ruby.new
10
+ code.exec "test/workers/fcc_filings_counter.rb"
11
+ code.runtime = "ruby"
12
+ code.merge_gem("nokogiri", "< 1.6.0") # keeps the build times low
13
+ code.merge_gem("ecfs")
14
+ code.full_remote_build(true)
15
+
16
+ batch.code = code
17
+ params = [
18
+ "12-375", "12-268",
19
+ "12-238", "12-353",
20
+ "13-150", "13-5",
21
+ "10-71"
22
+ ].map { |i| {docket_number: i} }
23
+ batch.params_array = params
21
24
  batch.create_code!
22
25
 
23
- results = batch.run!
26
+ results = batch.run!
24
27
 
25
28
  #binding.pry
26
29
 
27
30
  assert_equal batch.params_array.length, results.length
28
-
29
- results.select! {|r| !r.is_a?(IronResponse::Error)}
30
-
31
+ results.select! {|r| !r.is_a?(IronResponse::Log)}
31
32
  total = results.map {|r| r["length"]}.inject(:+)
32
-
33
33
  p "There are #{total} total filings in these dockets."
34
-
35
34
  assert_equal Array, results.class
36
35
  end
37
36
 
@@ -40,32 +39,30 @@ class GemDependencyTest < MiniTest::Unit::TestCase
40
39
  config = Configuration.keys
41
40
  batch = IronResponse::Batch.new(config)
42
41
 
43
- batch.worker = "test/workers/fcc_filings_counter.rb"
44
-
45
- batch.code.merge_gem("nokogiri", "< 1.6.0") # keeps the build times low
46
- batch.code.merge_gem("ecfs")
47
- batch.code.full_remote_build(true)
48
-
49
- batch.params_array = [
50
- "12-375", "12-268",
51
- "12-238", "12-353",
52
- "13-150", "13-5",
53
- "10-71"
54
- ].map { |i| {docket_number: i} }
42
+ code = IronWorkerNG::Code::Ruby.new
43
+ code.exec "test/workers/fcc_filings_counter.rb"
44
+ code.runtime = "ruby"
45
+ code.merge_gem("nokogiri", "< 1.6.0") # keeps the build times low
46
+ code.merge_gem("ecfs")
47
+ code.full_remote_build(true)
48
+
49
+ batch.code = code
50
+
51
+ params = [
52
+ "12-375", "12-268",
53
+ "12-238", "12-353",
54
+ "13-150", "13-5",
55
+ "10-71"
56
+ ].map { |i| {docket_number: i} }
57
+ batch.params_array = params
55
58
 
56
59
  batch.create_code!
57
60
  results = batch.run!
58
-
59
61
  assert_equal batch.params_array.length, results.length
60
-
61
62
  #binding.pry
62
-
63
- results.select! {|r| !r.is_a?(IronResponse::Error)}
64
-
63
+ results.select! {|r| !r.is_a?(IronResponse::Log)}
65
64
  total = results.map {|r| r["length"]}.inject(:+)
66
-
67
65
  p "There are #{total} total filings in these dockets."
68
-
69
66
  assert_equal Array, results.class
70
67
  end
71
68
 
@@ -4,39 +4,32 @@ class SynopsisTest < MiniTest::Unit::TestCase
4
4
  def test_synopsis_with_s3
5
5
  config = Configuration.keys
6
6
  batch = IronResponse::Batch.new(config)
7
-
8
- batch.worker = "test/workers/hello.rb"
9
- batch.params_array = Array(1..4).map {|i| {number: i}}
7
+ code = IronWorkerNG::Code::Ruby.new
8
+ code.runtime = "ruby"
9
+ code.exec "test/workers/hello.rb"
10
+ batch.code = code
11
+ batch.params_array = Array(1..4).map {|i| {number: i}}
10
12
  batch.create_code!
11
-
12
13
  results = batch.run!
13
-
14
14
  assert_equal batch.params_array.length, results.length
15
-
16
- results.select! {|r| !r.is_a?(IronResponse::Error)}
17
-
15
+ results.select! {|r| !r.is_a?(IronResponse::Log)}
18
16
  #binding.pry
19
-
20
17
  assert_equal Array, results.class
21
18
  end
22
19
 
23
20
  def test_synopsis_with_iron_cache
24
21
  config = Configuration.keys
25
22
  batch = IronResponse::Batch.new(iron_io: config[:iron_io])
26
-
27
- batch.worker = "test/workers/hello.rb"
28
- batch.params_array = Array(1..4).map {|i| {number: i}}
29
-
23
+ code = IronWorkerNG::Code::Ruby.new
24
+ code.runtime = "ruby"
25
+ code.exec "test/workers/hello.rb"
26
+ batch.code = code
27
+ batch.params_array = Array(1..4).map {|i| {number: i}}
30
28
  batch.create_code!
31
-
32
29
  results = batch.run!
33
-
34
30
  assert_equal batch.params_array.length, results.length
35
-
36
- results.select! {|r| !r.is_a?(IronResponse::Error)}
37
-
31
+ results.select! {|r| !r.is_a?(IronResponse::Log)}
38
32
  #binding.pry
39
-
40
33
  assert_equal Array, results.class
41
34
  end
42
35
  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.5
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-20 00:00:00.000000000 Z
12
+ date: 2013-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_worker_ng
@@ -123,7 +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
+ - lib/iron_response/log.rb
127
127
  - lib/iron_response/version.rb
128
128
  - lib/iron_response/worker.rb
129
129
  - test/configuration.rb.example