turbot-runner 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,9 @@ module TurbotRunner
3
3
  def handle_valid_record(record, data_type)
4
4
  end
5
5
 
6
+ def handle_run_ended
7
+ end
8
+
6
9
  def handle_invalid_record(record, data_type, line)
7
10
  end
8
11
 
@@ -12,18 +12,23 @@ module TurbotRunner
12
12
 
13
13
  def process(line)
14
14
  begin
15
- record = JSON.parse(line)
16
- errors = validate(record)
15
+ if line.strip == "RUN ENDED"
16
+ @record_handler.handle_run_ended
17
+ @runner.interrupt
18
+ else
19
+ record = JSON.parse(line)
20
+ errors = validate(record)
17
21
 
18
- if errors.empty?
19
- begin
20
- @record_handler.handle_valid_record(record, @data_type)
21
- rescue InterruptRun
22
- @runner.interrupt
22
+ if errors.empty?
23
+ begin
24
+ @record_handler.handle_valid_record(record, @data_type)
25
+ rescue InterruptRun
26
+ @runner.interrupt
27
+ end
28
+ else
29
+ @record_handler.handle_invalid_record(record, @data_type, errors)
30
+ @runner.interrupt_and_mark_as_failed
23
31
  end
24
- else
25
- @record_handler.handle_invalid_record(record, @data_type, errors)
26
- @runner.interrupt_and_mark_as_failed
27
32
  end
28
33
  rescue JSON::ParserError
29
34
  @record_handler.handle_invalid_json(line)
@@ -1,3 +1,3 @@
1
1
  module TurbotRunner
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -0,0 +1,8 @@
1
+ {
2
+ "bot_id": "bot-that-emits-run-ended",
3
+ "description": "This is a bot that emits RUN ENDED",
4
+ "language": "ruby",
5
+ "data_type": "primary data",
6
+ "identifying_fields": ["licence_number"],
7
+ "files": ["scraper.rb"]
8
+ }
@@ -0,0 +1,11 @@
1
+ require 'json'
2
+
3
+ 0.upto(2) do |n|
4
+ record = {
5
+ :licence_number => "XYZ#{n}",
6
+ :source_url => 'http://example.com',
7
+ :sample_date => '2014-06-01'
8
+ }
9
+ puts(record.to_json)
10
+ end
11
+ puts "RUN ENDED"
@@ -91,6 +91,25 @@ describe TurbotRunner::Runner do
91
91
  end
92
92
  end
93
93
 
94
+ context 'with a bot that outputs RUN ENDED' do
95
+ before do
96
+ @runner = TurbotRunner::Runner.new(
97
+ 'spec/bots/bot-that-emits-run-ended',
98
+ :log_to_file => true
99
+ )
100
+ end
101
+ it 'calls handle_run_ended on the handler' do
102
+ expect_any_instance_of(TurbotRunner::BaseHandler).to receive(:handle_run_ended)
103
+ @runner.run
104
+ end
105
+
106
+ it 'interrupts the run' do
107
+ expect_any_instance_of(TurbotRunner::ScriptRunner).to receive(:interrupt)
108
+ @runner.run
109
+ end
110
+ end
111
+
112
+
94
113
  context 'with a bot that crashes in scraper' do
95
114
  before do
96
115
  @runner = TurbotRunner::Runner.new(
@@ -209,7 +228,7 @@ describe TurbotRunner::Runner do
209
228
  @records_seen[data_type] += 1
210
229
  end
211
230
  end
212
-
231
+
213
232
  handler = Handler.new
214
233
  runner = TurbotRunner::Runner.new(
215
234
  'spec/bots/bot-with-transformer',
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbot-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - OpenCorporates
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-08-08 00:00:00.000000000 Z
12
+ date: 2014-08-12 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: json-schema
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - '='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - '='
25
28
  - !ruby/object:Gem::Version
@@ -39,34 +42,14 @@ files:
39
42
  - lib/turbot_runner/runner.rb
40
43
  - lib/turbot_runner/script_runner.rb
41
44
  - lib/turbot_runner/version.rb
42
- - schema/schemas/company-schema.json
43
- - schema/schemas/financial-payment-schema.json
44
- - schema/schemas/includes/address.json
45
- - schema/schemas/includes/alternative_name.json
46
- - schema/schemas/includes/company.json
47
- - schema/schemas/includes/filing.json
48
- - schema/schemas/includes/financial-payment-data-object.json
49
- - schema/schemas/includes/industry_code.json
50
- - schema/schemas/includes/licence-data-object.json
51
- - schema/schemas/includes/officer.json
52
- - schema/schemas/includes/previous_name.json
53
- - schema/schemas/includes/share-parcel-data.json
54
- - schema/schemas/includes/share-parcel.json
55
- - schema/schemas/includes/subsidiary-relationship-data.json
56
- - schema/schemas/includes/total-shares.json
57
- - schema/schemas/licence-schema.json
58
- - schema/schemas/primary-data-schema.json
59
- - schema/schemas/share-parcel-schema.json
60
- - schema/schemas/simple-financial-payment-schema.json
61
- - schema/schemas/simple-licence-schema.json
62
- - schema/schemas/simple-subsidiary-schema.json
63
- - schema/schemas/subsidiary-relationship-schema.json
64
45
  - spec/bots/bot-that-crashes-in-scraper/manifest.json
65
46
  - spec/bots/bot-that-crashes-in-scraper/scraper.rb
66
47
  - spec/bots/bot-that-crashes-in-transformer/manifest.json
67
48
  - spec/bots/bot-that-crashes-in-transformer/scraper.rb
68
49
  - spec/bots/bot-that-crashes-in-transformer/transformer1.rb
69
50
  - spec/bots/bot-that-crashes-in-transformer/transformer2.rb
51
+ - spec/bots/bot-that-emits-run-ended/manifest.json
52
+ - spec/bots/bot-that-emits-run-ended/scraper.rb
70
53
  - spec/bots/bot-with-pause/manifest.json
71
54
  - spec/bots/bot-with-pause/scraper.rb
72
55
  - spec/bots/bot-with-transformer/manifest.json
@@ -94,29 +77,51 @@ files:
94
77
  - spec/outputs/full-scraper.out
95
78
  - spec/outputs/full-transformer.out
96
79
  - spec/outputs/truncated-scraper.out
80
+ - schema/schemas/company-schema.json
81
+ - schema/schemas/financial-payment-schema.json
82
+ - schema/schemas/includes/address.json
83
+ - schema/schemas/includes/alternative_name.json
84
+ - schema/schemas/includes/company.json
85
+ - schema/schemas/includes/filing.json
86
+ - schema/schemas/includes/financial-payment-data-object.json
87
+ - schema/schemas/includes/industry_code.json
88
+ - schema/schemas/includes/licence-data-object.json
89
+ - schema/schemas/includes/officer.json
90
+ - schema/schemas/includes/previous_name.json
91
+ - schema/schemas/includes/share-parcel-data.json
92
+ - schema/schemas/includes/share-parcel.json
93
+ - schema/schemas/includes/subsidiary-relationship-data.json
94
+ - schema/schemas/includes/total-shares.json
95
+ - schema/schemas/licence-schema.json
96
+ - schema/schemas/primary-data-schema.json
97
+ - schema/schemas/share-parcel-schema.json
98
+ - schema/schemas/simple-financial-payment-schema.json
99
+ - schema/schemas/simple-licence-schema.json
100
+ - schema/schemas/simple-subsidiary-schema.json
101
+ - schema/schemas/subsidiary-relationship-schema.json
97
102
  homepage: http://turbot.opencorporates.com/
98
103
  licenses:
99
104
  - MIT
100
- metadata: {}
101
105
  post_install_message:
102
106
  rdoc_options: []
103
107
  require_paths:
104
108
  - lib
105
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
106
111
  requirements:
107
112
  - - ! '>='
108
113
  - !ruby/object:Gem::Version
109
114
  version: 1.9.2
110
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
111
117
  requirements:
112
118
  - - ! '>='
113
119
  - !ruby/object:Gem::Version
114
120
  version: '0'
115
121
  requirements: []
116
122
  rubyforge_project:
117
- rubygems_version: 2.2.2
123
+ rubygems_version: 1.8.23
118
124
  signing_key:
119
- specification_version: 4
125
+ specification_version: 3
120
126
  summary: Utilities for running bots with Turbot
121
127
  test_files: []
122
- has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2Q4MGEyNmViMzEzODU2YWJkNTRkNjY2NzQ4N2JkODUzYmM3MTVhOQ==
5
- data.tar.gz: !binary |-
6
- MjJhZTJjZjMwYmZjNTY5Mjk3YWU4OTUwMTA1M2I4MjNiZWFiNzVlYw==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- ZjYzMTZhODVkNmU3MWE3ZjkzNTNkMzRhNzZjMWUzODlhODc0YmFlODhlMWE3
10
- YzUxMDU3Y2E5MTBhZTg2MTY3MjIyMDNkZmE2OTIwOWI1M2RmMTQ4MDQzODlm
11
- MjE0MGMzNTc2NjZlZWI5MGI5NTgxZTQzZDRkYmE4YzUxZjAzOWE=
12
- data.tar.gz: !binary |-
13
- ZGE3NDZmZGRhYWI2NjNlZTM4MWExYzg3MmZiYzNiMzExMTFhZDlkYWVhOTIy
14
- MTk3Mzk1NTU3Y2RhZDY2ZGQ1Yzc5ZTg0YTMxMmQyN2Y0YzVmMjA5ZjVlODk4
15
- MDg1MDQ0ZWI4MDk1ZWZjZjk2ZmMyOTEwMDY5Mzc5NjFjZWRjZjg=