rodimus 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rodimus/step.rb +30 -16
- data/lib/rodimus/transformation.rb +13 -4
- data/lib/rodimus/version.rb +1 -1
- data/lib/rodimus.rb +2 -0
- data/test/step_test.rb +26 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5492a6a648768bd138246fd1137174a1d424da95
|
4
|
+
data.tar.gz: 6f8a62c081ba530005953def9e3be5e95b56a8e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2d871ad7e844d562a60b0d39d08712b3a53ad56cc866326780c60cf86615aaecdd57da6fa05f84cb02644848ab4876ab47e2b1b45431424a839c4ffdf459c13
|
7
|
+
data.tar.gz: 4ce9fa3f5d99e63aef2643f25b56f50ad14081cd1cae52f8b2223de5e8184e06effc91d7da19d9e85ab98e5f329ddb831ba442bbf30cb888f0fd71e566ebe977
|
data/lib/rodimus/step.rb
CHANGED
@@ -1,7 +1,34 @@
|
|
1
1
|
module Rodimus
|
2
2
|
|
3
3
|
module Step
|
4
|
-
|
4
|
+
# The incoming data stream. Can be anything that quacks like an IO
|
5
|
+
attr_accessor :incoming
|
6
|
+
|
7
|
+
# The outgoing data stream. Can be anything that quacks like an IO
|
8
|
+
attr_accessor :outgoing
|
9
|
+
|
10
|
+
# Shared user-data accessible across all running transformation steps.
|
11
|
+
# This is initialized by the Transformation when the step begins to run.
|
12
|
+
attr_accessor :shared_data
|
13
|
+
|
14
|
+
def close_descriptors
|
15
|
+
[incoming, outgoing].reject(&:nil?).each do |descriptor|
|
16
|
+
descriptor.close if descriptor.respond_to?(:close)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Override this for custom cleanup functionality.
|
21
|
+
def finalize; end
|
22
|
+
|
23
|
+
# Override this for custom output handling functionality per-row.
|
24
|
+
def handle_output(transformed_row)
|
25
|
+
outgoing.puts(transformed_row)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Override this for custom transformation functionality
|
29
|
+
def process_row(row)
|
30
|
+
row.to_s
|
31
|
+
end
|
5
32
|
|
6
33
|
def run
|
7
34
|
Rodimus.logger.info "Running #{self}"
|
@@ -11,26 +38,13 @@ module Rodimus
|
|
11
38
|
end
|
12
39
|
finalize
|
13
40
|
Rodimus.logger.info "Finished #{self}"
|
41
|
+
ensure
|
42
|
+
close_descriptors
|
14
43
|
end
|
15
44
|
|
16
45
|
def to_s
|
17
46
|
"#{self.class} connected to input: #{incoming} and output: #{outgoing}"
|
18
47
|
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# Override this for custom functionality
|
23
|
-
def finalize; end
|
24
|
-
|
25
|
-
# Override this for custom functionality
|
26
|
-
def handle_output(transformed_row)
|
27
|
-
outgoing.puts(transformed_row)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Override this for custom functionality
|
31
|
-
def process_row(row)
|
32
|
-
row.to_s
|
33
|
-
end
|
34
48
|
end
|
35
49
|
|
36
50
|
end
|
@@ -1,24 +1,33 @@
|
|
1
|
+
require 'drb'
|
2
|
+
|
1
3
|
module Rodimus
|
2
4
|
|
3
5
|
class Transformation
|
4
|
-
attr_reader :steps
|
6
|
+
attr_reader :drb_server, :steps
|
7
|
+
|
8
|
+
# User-data accessible across all running steps.
|
9
|
+
attr_reader :shared_data
|
5
10
|
|
6
11
|
def initialize
|
7
12
|
@steps = []
|
13
|
+
@shared_data = {} # TODO: This needs to be thread safe
|
8
14
|
end
|
9
15
|
|
10
16
|
def run
|
17
|
+
@drb_server = DRb.start_service(nil, shared_data)
|
11
18
|
prepare
|
12
19
|
|
13
20
|
steps.each do |step|
|
14
21
|
fork do
|
22
|
+
DRb.start_service # the parent DRb thread dies across the fork
|
23
|
+
step.shared_data = DRbObject.new_with_uri(drb_server.uri)
|
15
24
|
step.run
|
16
25
|
end
|
17
|
-
step.
|
18
|
-
step.outgoing && step.outgoing.close
|
26
|
+
step.close_descriptors
|
19
27
|
end
|
20
|
-
|
28
|
+
ensure
|
21
29
|
Process.waitall
|
30
|
+
drb_server.stop_service
|
22
31
|
end
|
23
32
|
|
24
33
|
def to_s
|
data/lib/rodimus/version.rb
CHANGED
data/lib/rodimus.rb
CHANGED
data/test/step_test.rb
CHANGED
@@ -5,37 +5,43 @@ module Rodimus
|
|
5
5
|
Rodimus.configure do |config|
|
6
6
|
config.logger = Logger.new(nil)
|
7
7
|
end
|
8
|
+
|
9
|
+
class TestIO < IO
|
10
|
+
attr_reader :history
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@history = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def close; nil; end
|
17
|
+
|
18
|
+
def puts(string)
|
19
|
+
history << string
|
20
|
+
end
|
21
|
+
end
|
8
22
|
|
9
23
|
class TestStep < MiniTest::Unit::TestCase
|
10
24
|
def setup
|
11
25
|
@test_string = "row 1\nrow 2"
|
12
26
|
@incoming = StringIO.new(@test_string)
|
13
|
-
@outgoing =
|
27
|
+
@outgoing = TestIO.new
|
28
|
+
@step = Object.new
|
29
|
+
@step.extend(Rodimus::Step)
|
30
|
+
@step.incoming = @incoming
|
31
|
+
@step.outgoing = @outgoing
|
14
32
|
end
|
15
33
|
|
16
34
|
def test_streaming_rows
|
17
|
-
step
|
18
|
-
|
19
|
-
step.incoming = @incoming
|
20
|
-
step.outgoing = @outgoing
|
21
|
-
step.run
|
22
|
-
@outgoing.rewind
|
23
|
-
assert_equal @test_string, @outgoing.read.chomp
|
35
|
+
@step.run
|
36
|
+
assert_equal @test_string, @outgoing.history.join
|
24
37
|
end
|
25
38
|
|
26
39
|
def test_process_row
|
27
|
-
step
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
end.new
|
34
|
-
step.incoming = @incoming
|
35
|
-
step.outgoing = @outgoing
|
36
|
-
step.run
|
37
|
-
@outgoing.rewind
|
38
|
-
assert_equal @test_string.upcase, @outgoing.read.chomp
|
40
|
+
@step.define_singleton_method(:process_row) do |row|
|
41
|
+
row.upcase
|
42
|
+
end
|
43
|
+
@step.run
|
44
|
+
assert_equal @test_string.upcase, @outgoing.history.join
|
39
45
|
end
|
40
46
|
end
|
41
47
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rodimus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Rice
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|