turbot-runner 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,24 +16,20 @@ module TurbotRunner
16
16
 
17
17
  def run
18
18
  FileUtils.mkdir_p(@output_directory)
19
-
20
- return false if not run_script(scraper_config)
21
-
19
+ succeeded = run_script(scraper_config)
20
+ # Run the transformers even if the scraper fails
22
21
  transformers.each do |transformer_config|
23
- return false if not run_script(transformer_config, input_file=scraper_output_file)
22
+ succeeded = run_script(transformer_config, input_file=scraper_output_file) && succeeded
24
23
  end
25
-
26
- true
24
+ succeeded
27
25
  end
28
26
 
29
27
  def process_output
30
- return false if not process_script_output(scraper_config)
28
+ process_script_output(scraper_config)
31
29
 
32
30
  transformers.each do |transformer_config|
33
- return false if not process_script_output(transformer_config)
31
+ process_script_output(transformer_config)
34
32
  end
35
-
36
- true
37
33
  end
38
34
 
39
35
  private
@@ -53,7 +49,7 @@ module TurbotRunner
53
49
  def run_script(script_config, input_file=nil)
54
50
  command = build_command(script_config[:file], input_file)
55
51
 
56
- runner = ScriptRunner.new(
52
+ script_runner = ScriptRunner.new(
57
53
  command,
58
54
  output_file(script_config[:file]),
59
55
  script_config,
@@ -61,7 +57,7 @@ module TurbotRunner
61
57
  :timeout => @timeout
62
58
  )
63
59
 
64
- runner.run
60
+ script_runner.run # returns boolean indicating success
65
61
  end
66
62
 
67
63
  def process_script_output(script_config)
@@ -1,3 +1,3 @@
1
1
  module TurbotRunner
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
@@ -4,5 +4,12 @@
4
4
  "language": "ruby",
5
5
  "data_type": "primary data",
6
6
  "identifying_fields": ["licence_number"],
7
- "files": ["scraper.rb"]
7
+ "files": ["scraper.rb", "transformer1.rb"],
8
+ "transformers": [
9
+ {
10
+ "file": "transformer1.rb",
11
+ "data_type": "simple-licence",
12
+ "identifying_fields": ["licence_number"]
13
+ }
14
+ ]
8
15
  }
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+
3
+ STDIN.each_line do |line|
4
+ raw_record = JSON.parse(line)
5
+
6
+ transformed_record = {
7
+ :company_name => 'Foo Widgets',
8
+ :company_jurisdiction => 'gb',
9
+ :licence_number => raw_record['licence_number'],
10
+ :source_url => raw_record['source_url'],
11
+ :sample_date => raw_record['sample_date'],
12
+ }
13
+
14
+ puts transformed_record.to_json
15
+ end
@@ -126,6 +126,14 @@ describe TurbotRunner::Runner do
126
126
  @runner.run
127
127
  expect([@runner, 'scraper']).to have_error_output_matching(/Oh no/)
128
128
  end
129
+
130
+ it 'still runs the transformers' do
131
+ expect(@runner).to receive(:run_script).once.with(
132
+ hash_including(:file=>"scraper.rb"))
133
+ expect(@runner).to receive(:run_script).once.with(
134
+ hash_including(:file=>"transformer1.rb"), anything)
135
+ @runner.run
136
+ end
129
137
  end
130
138
 
131
139
  context 'with a bot that crashes in transformer' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbot-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
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: 2014-11-18 00:00:00.000000000 Z
12
+ date: 2014-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json-schema
@@ -44,6 +44,7 @@ files:
44
44
  - lib/turbot_runner/version.rb
45
45
  - spec/bots/bot-that-crashes-in-scraper/manifest.json
46
46
  - spec/bots/bot-that-crashes-in-scraper/scraper.rb
47
+ - spec/bots/bot-that-crashes-in-scraper/transformer1.rb
47
48
  - spec/bots/bot-that-crashes-in-transformer/manifest.json
48
49
  - spec/bots/bot-that-crashes-in-transformer/scraper.rb
49
50
  - spec/bots/bot-that-crashes-in-transformer/transformer1.rb