exel 0.0.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.rspec +2 -1
- data/exel.gemspec +9 -2
- data/lib/exel/ast_node.rb +30 -0
- data/lib/exel/context.rb +79 -0
- data/lib/exel/deferred_context_value.rb +18 -0
- data/lib/exel/error/job_termination.rb +10 -0
- data/lib/exel/execution_worker.rb +13 -0
- data/lib/exel/handlers/s3_handler.rb +43 -0
- data/lib/exel/handlers/sidekiq_handler.rb +21 -0
- data/lib/exel/instruction.rb +17 -0
- data/lib/exel/instruction_node.rb +9 -0
- data/lib/exel/job.rb +74 -0
- data/lib/exel/logging.rb +30 -0
- data/lib/exel/null_instruction.rb +6 -0
- data/lib/exel/processor_helper.rb +67 -0
- data/lib/exel/processors/async_processor.rb +24 -0
- data/lib/exel/processors/split_processor.rb +85 -0
- data/lib/exel/resource.rb +35 -0
- data/lib/exel/sequence_node.rb +14 -0
- data/lib/exel/version.rb +1 -1
- data/lib/exel.rb +19 -1
- data/spec/exel/ast_node_spec.rb +52 -0
- data/spec/exel/context_spec.rb +151 -0
- data/spec/exel/deferred_context_value_spec.rb +21 -0
- data/spec/exel/execution_worker_spec.rb +13 -0
- data/spec/exel/handlers/s3_handler_spec.rb +49 -0
- data/spec/exel/handlers/sidekiq_handler_spec.rb +54 -0
- data/spec/exel/instruction_node_spec.rb +22 -0
- data/spec/exel/instruction_spec.rb +58 -0
- data/spec/exel/job_spec.rb +215 -0
- data/spec/exel/logging_spec.rb +36 -0
- data/spec/exel/null_instruction_spec.rb +5 -0
- data/spec/exel/processors/async_processor_spec.rb +16 -0
- data/spec/exel/processors/split_processor_spec.rb +90 -0
- data/spec/exel/resource_spec.rb +51 -0
- data/spec/exel/sequence_node_spec.rb +24 -0
- data/spec/spec_helper.rb +7 -0
- metadata +151 -18
@@ -0,0 +1,16 @@
|
|
1
|
+
module EXEL
|
2
|
+
module Processors
|
3
|
+
describe AsyncProcessor do
|
4
|
+
subject(:processor) { AsyncProcessor.new(context) }
|
5
|
+
let(:context) { EXEL::Context.new }
|
6
|
+
let(:block) { instance_double(SequenceNode) }
|
7
|
+
|
8
|
+
describe '#process' do
|
9
|
+
it 'should call do_async on the async handler' do
|
10
|
+
expect(processor.handler).to receive(:do_async).with(block)
|
11
|
+
processor.process(block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module EXEL
|
2
|
+
module Processors
|
3
|
+
describe SplitProcessor do
|
4
|
+
let(:chunk_file) { instance_double(File) }
|
5
|
+
let(:file) { create_file(1) }
|
6
|
+
let(:context) { Context.new(resource: file) }
|
7
|
+
let(:callback) { instance_double(SequenceNode) }
|
8
|
+
subject(:splitter) { SplitProcessor.new(context) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
allow_any_instance_of(StringIO).to receive(:path).and_return('/text.txt')
|
12
|
+
allow(File).to receive(:delete)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#process' do
|
16
|
+
let(:file) { create_file(3) }
|
17
|
+
|
18
|
+
it 'should process file with 3 lines line by line' do
|
19
|
+
allow(CSV).to receive(:foreach).and_yield("line0").and_yield("line1").and_yield("line2")
|
20
|
+
|
21
|
+
3.times do |i|
|
22
|
+
expect(splitter).to receive(:process_line).with("line#{i}", callback)
|
23
|
+
end
|
24
|
+
expect(splitter).to receive(:process_line).with(:eof, callback)
|
25
|
+
|
26
|
+
expect(File).to receive(:delete).with(file.path)
|
27
|
+
|
28
|
+
splitter.process(callback)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should abort parsing the csv file if it is malformed' do
|
32
|
+
allow(CSV).to receive(:foreach).and_raise(CSV::MalformedCSVError)
|
33
|
+
expect(splitter).to receive(:process_line).with(:eof, callback)
|
34
|
+
|
35
|
+
splitter.process(callback)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#process_line' do
|
40
|
+
[
|
41
|
+
{input: 1, chunks: %W(0\n)},
|
42
|
+
{input: 3, chunks: %W(0\n1\n 2\n)},
|
43
|
+
{input: 4, chunks: %W(0\n1\n 2\n3\n)}
|
44
|
+
].each do |data|
|
45
|
+
it "should produce #{data[:chunks].size} chunks with #{data[:input]} input lines" do
|
46
|
+
splitter.chunk_size = 2
|
47
|
+
|
48
|
+
data[:chunks].each do |chunk|
|
49
|
+
expect(splitter).to receive(:generate_chunk).with(chunk).and_return(chunk_file)
|
50
|
+
expect(callback).to receive(:run).with(context) do
|
51
|
+
expect(context[:resource]).to eq(chunk_file)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
data[:input].times { |i| splitter.process_line([i.to_s], callback) }
|
56
|
+
splitter.process_line(:eof, callback)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#generate_chunk' do
|
62
|
+
it 'should create a file with the contents of the given string' do
|
63
|
+
file = splitter.generate_chunk('abc')
|
64
|
+
content = file.read
|
65
|
+
expect(content).to eq('abc')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should create a file with a unique name' do
|
69
|
+
3.times do |i|
|
70
|
+
index = i + 1
|
71
|
+
file = splitter.generate_chunk("#{index}")
|
72
|
+
file_name = splitter.filename(file)
|
73
|
+
expect(file_name).to include("text_#{index}_")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_file(lines)
|
79
|
+
content = ''
|
80
|
+
|
81
|
+
lines.times do |i|
|
82
|
+
line = CSV.generate_line(["line#{i}"])
|
83
|
+
content << line
|
84
|
+
end
|
85
|
+
|
86
|
+
StringIO.new content
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module EXEL
|
2
|
+
describe Resource do
|
3
|
+
let(:s3_uri) { 's3://test_file.csv' }
|
4
|
+
|
5
|
+
describe '.remotize' do
|
6
|
+
context 'when passed in value is not a file' do
|
7
|
+
it 'should return the value' do
|
8
|
+
expect(Resource.remotize('test string')).to eq('test string')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when the passed in value is a file' do
|
13
|
+
[File, Tempfile].each do |file_class|
|
14
|
+
context "with a #{file_class}" do
|
15
|
+
before do
|
16
|
+
@file = instance_double(file_class)
|
17
|
+
allow(@file).to receive(:is_a?) { |klass| klass == file_class }
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should upload the file to S3' do
|
21
|
+
expect_any_instance_of(Handlers::S3Handler).to receive(:upload).with(@file)
|
22
|
+
Resource.remotize(@file)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return a remote file URI' do
|
26
|
+
allow_any_instance_of(Handlers::S3Handler).to receive(:upload).with(@file).and_return(s3_uri)
|
27
|
+
expect(Resource.remotize(@file)).to eq(s3_uri)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.localize' do
|
35
|
+
context 'with a localized value' do
|
36
|
+
it 'should return the value' do
|
37
|
+
expect(Resource.localize('test string')).to eq('test string')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with a remote file' do
|
42
|
+
it 'should return the downloaded file' do
|
43
|
+
file = double(:file)
|
44
|
+
expect_any_instance_of(Handlers::S3Handler).to receive(:download).with(s3_uri).and_return(file)
|
45
|
+
|
46
|
+
expect(Resource.localize(s3_uri)).to eq(file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module EXEL
|
2
|
+
describe SequenceNode do
|
3
|
+
let(:context) { {} }
|
4
|
+
|
5
|
+
def build_tree
|
6
|
+
@node_2 = instance_double(ASTNode)
|
7
|
+
@node_3 = instance_double(ASTNode)
|
8
|
+
@node_1 = SequenceNode.new(@node_2, @node_3)
|
9
|
+
end
|
10
|
+
|
11
|
+
it { is_expected.to be_kind_of(ASTNode) }
|
12
|
+
|
13
|
+
describe '#run' do
|
14
|
+
before { build_tree }
|
15
|
+
|
16
|
+
it 'should run each child node in sequence' do
|
17
|
+
expect(@node_2).to receive(:run).with(context).once.ordered
|
18
|
+
expect(@node_3).to receive(:run).with(context).once.ordered
|
19
|
+
|
20
|
+
@node_1.run(context)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,57 +1,141 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yroo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
|
-
- - ~>
|
45
|
+
- - "~>"
|
18
46
|
- !ruby/object:Gem::Version
|
19
47
|
version: '1.6'
|
20
48
|
type: :development
|
21
49
|
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
|
-
- - ~>
|
52
|
+
- - "~>"
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '1.6'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rake
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
|
-
- -
|
59
|
+
- - "~>"
|
32
60
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
61
|
+
version: '10'
|
34
62
|
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
|
-
- -
|
66
|
+
- - "~>"
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
68
|
+
version: '10'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rspec
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
|
-
- -
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: terminal-notifier
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: terminal-notifier-guard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
46
130
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
131
|
+
version: '1'
|
48
132
|
type: :development
|
49
133
|
prerelease: false
|
50
134
|
version_requirements: !ruby/object:Gem::Requirement
|
51
135
|
requirements:
|
52
|
-
- -
|
136
|
+
- - "~>"
|
53
137
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
138
|
+
version: '1'
|
55
139
|
description: A DSL for defining jobs that can be run in a highly scalable manner
|
56
140
|
email:
|
57
141
|
- dev@yroo.com
|
@@ -59,8 +143,8 @@ executables: []
|
|
59
143
|
extensions: []
|
60
144
|
extra_rdoc_files: []
|
61
145
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .rspec
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
64
148
|
- Gemfile
|
65
149
|
- Guardfile
|
66
150
|
- LICENSE.txt
|
@@ -68,7 +152,40 @@ files:
|
|
68
152
|
- Rakefile
|
69
153
|
- exel.gemspec
|
70
154
|
- lib/exel.rb
|
155
|
+
- lib/exel/ast_node.rb
|
156
|
+
- lib/exel/context.rb
|
157
|
+
- lib/exel/deferred_context_value.rb
|
158
|
+
- lib/exel/error/job_termination.rb
|
159
|
+
- lib/exel/execution_worker.rb
|
160
|
+
- lib/exel/handlers/s3_handler.rb
|
161
|
+
- lib/exel/handlers/sidekiq_handler.rb
|
162
|
+
- lib/exel/instruction.rb
|
163
|
+
- lib/exel/instruction_node.rb
|
164
|
+
- lib/exel/job.rb
|
165
|
+
- lib/exel/logging.rb
|
166
|
+
- lib/exel/null_instruction.rb
|
167
|
+
- lib/exel/processor_helper.rb
|
168
|
+
- lib/exel/processors/async_processor.rb
|
169
|
+
- lib/exel/processors/split_processor.rb
|
170
|
+
- lib/exel/resource.rb
|
171
|
+
- lib/exel/sequence_node.rb
|
71
172
|
- lib/exel/version.rb
|
173
|
+
- spec/exel/ast_node_spec.rb
|
174
|
+
- spec/exel/context_spec.rb
|
175
|
+
- spec/exel/deferred_context_value_spec.rb
|
176
|
+
- spec/exel/execution_worker_spec.rb
|
177
|
+
- spec/exel/handlers/s3_handler_spec.rb
|
178
|
+
- spec/exel/handlers/sidekiq_handler_spec.rb
|
179
|
+
- spec/exel/instruction_node_spec.rb
|
180
|
+
- spec/exel/instruction_spec.rb
|
181
|
+
- spec/exel/job_spec.rb
|
182
|
+
- spec/exel/logging_spec.rb
|
183
|
+
- spec/exel/null_instruction_spec.rb
|
184
|
+
- spec/exel/processors/async_processor_spec.rb
|
185
|
+
- spec/exel/processors/split_processor_spec.rb
|
186
|
+
- spec/exel/resource_spec.rb
|
187
|
+
- spec/exel/sequence_node_spec.rb
|
188
|
+
- spec/spec_helper.rb
|
72
189
|
homepage: https://github.com/47colborne/exel
|
73
190
|
licenses:
|
74
191
|
- MIT
|
@@ -79,18 +196,34 @@ require_paths:
|
|
79
196
|
- lib
|
80
197
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
198
|
requirements:
|
82
|
-
- -
|
199
|
+
- - ">="
|
83
200
|
- !ruby/object:Gem::Version
|
84
201
|
version: '0'
|
85
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
203
|
requirements:
|
87
|
-
- -
|
204
|
+
- - ">="
|
88
205
|
- !ruby/object:Gem::Version
|
89
206
|
version: '0'
|
90
207
|
requirements: []
|
91
208
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
209
|
+
rubygems_version: 2.4.5.1
|
93
210
|
signing_key:
|
94
211
|
specification_version: 4
|
95
212
|
summary: EXEL, the Elastic eXEcution Language
|
96
|
-
test_files:
|
213
|
+
test_files:
|
214
|
+
- spec/exel/ast_node_spec.rb
|
215
|
+
- spec/exel/context_spec.rb
|
216
|
+
- spec/exel/deferred_context_value_spec.rb
|
217
|
+
- spec/exel/execution_worker_spec.rb
|
218
|
+
- spec/exel/handlers/s3_handler_spec.rb
|
219
|
+
- spec/exel/handlers/sidekiq_handler_spec.rb
|
220
|
+
- spec/exel/instruction_node_spec.rb
|
221
|
+
- spec/exel/instruction_spec.rb
|
222
|
+
- spec/exel/job_spec.rb
|
223
|
+
- spec/exel/logging_spec.rb
|
224
|
+
- spec/exel/null_instruction_spec.rb
|
225
|
+
- spec/exel/processors/async_processor_spec.rb
|
226
|
+
- spec/exel/processors/split_processor_spec.rb
|
227
|
+
- spec/exel/resource_spec.rb
|
228
|
+
- spec/exel/sequence_node_spec.rb
|
229
|
+
- spec/spec_helper.rb
|