turbot-runner 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module TurbotRunner
|
|
14
14
|
begin
|
15
15
|
if line.strip == "RUN ENDED"
|
16
16
|
@record_handler.handle_run_ended
|
17
|
-
@runner.interrupt
|
17
|
+
@runner.interrupt if @runner
|
18
18
|
else
|
19
19
|
record = JSON.parse(line)
|
20
20
|
errors = validate(record)
|
@@ -23,16 +23,16 @@ module TurbotRunner
|
|
23
23
|
begin
|
24
24
|
@record_handler.handle_valid_record(record, @data_type)
|
25
25
|
rescue InterruptRun
|
26
|
-
@runner.interrupt
|
26
|
+
@runner.interrupt if @runner
|
27
27
|
end
|
28
28
|
else
|
29
29
|
@record_handler.handle_invalid_record(record, @data_type, errors)
|
30
|
-
@runner.interrupt_and_mark_as_failed
|
30
|
+
@runner.interrupt_and_mark_as_failed if @runner
|
31
31
|
end
|
32
32
|
end
|
33
33
|
rescue JSON::ParserError
|
34
34
|
@record_handler.handle_invalid_json(line)
|
35
|
-
@runner.interrupt_and_mark_as_failed
|
35
|
+
@runner.interrupt_and_mark_as_failed if @runner
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
data/lib/turbot_runner/runner.rb
CHANGED
@@ -65,6 +65,10 @@ module TurbotRunner
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def process_script_output(script_config)
|
68
|
+
# The first argument to the Processor constructor is a nil
|
69
|
+
# Runner. This is because no running behaviour
|
70
|
+
# (e.g. interruptions etc) is required; we just want to do
|
71
|
+
# record handling.
|
68
72
|
processor = Processor.new(nil, script_config, @record_handler)
|
69
73
|
|
70
74
|
File.open(output_file(script_config[:file])) do |f|
|
@@ -130,9 +130,11 @@
|
|
130
130
|
"minLength": 1
|
131
131
|
},
|
132
132
|
"number_of_employees": {
|
133
|
-
"
|
134
|
-
|
135
|
-
|
133
|
+
"anyOf": [
|
134
|
+
{"type":"string","minLength": 1},
|
135
|
+
{"type":"number","minimum": 0}
|
136
|
+
],
|
137
|
+
"description": "The number of employees"
|
136
138
|
},
|
137
139
|
"merged_into": {
|
138
140
|
"type": "object",
|
data/spec/lib/processor_spec.rb
CHANGED
@@ -6,64 +6,91 @@ describe TurbotRunner::Processor do
|
|
6
6
|
before do
|
7
7
|
@handler = TurbotRunner::BaseHandler.new
|
8
8
|
@data_type = 'primary data'
|
9
|
-
script_config = {
|
9
|
+
@script_config = {
|
10
10
|
:data_type => @data_type,
|
11
11
|
:identifying_fields => ['number']
|
12
12
|
}
|
13
|
-
script_runner = instance_double('ScriptRunner')
|
14
|
-
allow(script_runner).to receive(:interrupt_and_mark_as_failed)
|
15
|
-
@processor = TurbotRunner::Processor.new(script_runner, script_config, @handler)
|
16
13
|
end
|
17
14
|
|
18
|
-
context 'with
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
context 'with a nil runner passed in' do
|
16
|
+
before do
|
17
|
+
@processor = TurbotRunner::Processor.new(nil, @script_config, @handler)
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with record missing required field' do
|
21
|
+
before do
|
22
|
+
@record = {
|
23
|
+
'sample_date' => '2014-06-01',
|
24
|
+
'number' => 123
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'calls Handler#handle_invalid_record' do
|
29
|
+
expected_errors = ['Missing required attribute: source_url']
|
30
|
+
expect(@handler).to receive(:handle_invalid_record).
|
31
|
+
with(@record, @data_type, expected_errors)
|
32
|
+
@processor.process(@record.to_json)
|
33
|
+
end
|
27
34
|
end
|
28
35
|
end
|
29
36
|
|
30
|
-
context 'with
|
37
|
+
context 'with a runner passed in' do
|
31
38
|
before do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
39
|
+
script_runner = instance_double('ScriptRunner')
|
40
|
+
allow(script_runner).to receive(:interrupt_and_mark_as_failed)
|
41
|
+
@processor = TurbotRunner::Processor.new(script_runner, @script_config, @handler)
|
36
42
|
end
|
37
43
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
context 'with valid record' do
|
45
|
+
it 'calls Handler#handle_valid_record' do
|
46
|
+
record = {
|
47
|
+
'sample_date' => '2014-06-01',
|
48
|
+
'source_url' => 'http://example.com/123',
|
49
|
+
'number' => 123
|
50
|
+
}
|
51
|
+
expect(@handler).to receive(:handle_valid_record).with(record, @data_type)
|
52
|
+
@processor.process(record.to_json)
|
53
|
+
end
|
43
54
|
end
|
44
|
-
end
|
45
55
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
context 'with record missing required field' do
|
57
|
+
before do
|
58
|
+
@record = {
|
59
|
+
'sample_date' => '2014-06-01',
|
60
|
+
'number' => 123
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'calls Handler#handle_invalid_record' do
|
65
|
+
expected_errors = ['Missing required attribute: source_url']
|
66
|
+
expect(@handler).to receive(:handle_invalid_record).
|
67
|
+
with(@record, @data_type, expected_errors)
|
68
|
+
@processor.process(@record.to_json)
|
69
|
+
end
|
52
70
|
end
|
53
71
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
72
|
+
context 'with record missing all identifying fields' do
|
73
|
+
before do
|
74
|
+
@record = {
|
75
|
+
'sample_date' => '2014-06-01',
|
76
|
+
'source_url' => 'http://example.com/123'
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'calls Handler#handle_invalid_record' do
|
81
|
+
expected_errors = ['There were no values provided for any of the identifying fields: number']
|
82
|
+
expect(@handler).to receive(:handle_invalid_record).
|
83
|
+
with(@record, @data_type, expected_errors)
|
84
|
+
@processor.process(@record.to_json)
|
85
|
+
end
|
59
86
|
end
|
60
|
-
end
|
61
87
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
88
|
+
context 'with invalid JSON' do
|
89
|
+
it 'calls Handler#handle_invalid_json' do
|
90
|
+
line = 'this is not JSON'
|
91
|
+
expect(@handler).to receive(:handle_invalid_json).with(line)
|
92
|
+
@processor.process(line)
|
93
|
+
end
|
67
94
|
end
|
68
95
|
end
|
69
96
|
end
|
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.
|
4
|
+
version: 0.1.9
|
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-
|
12
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json-schema
|