rodimus 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 090665c626ab20b21e745069db326cb87716c352
4
- data.tar.gz: 9b36aa2309d9f4d3eba3422e5240165e1bd325af
3
+ metadata.gz: 5492a6a648768bd138246fd1137174a1d424da95
4
+ data.tar.gz: 6f8a62c081ba530005953def9e3be5e95b56a8e5
5
5
  SHA512:
6
- metadata.gz: 150a93c771af7841c7e259054adc2cdfee0be8a665078cd363f43c82648a6b0278a3f0a91bb88dbb974ab72fd12576de6cc9e33bae710fa764808836d118ef5b
7
- data.tar.gz: b0e276b1e7bc47201736a428fd39360026b37a4f801a5cf8340e9fc8bcf3fc31fa5f734f5eb1306fc4c1417f1d38fcf0ebd6709c151009fe45cacaf02c622755
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
- attr_accessor :incoming, :outgoing
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.incoming && step.incoming.close
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
@@ -1,3 +1,3 @@
1
1
  module Rodimus
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/rodimus.rb CHANGED
@@ -4,6 +4,8 @@ require 'rodimus/transformation'
4
4
  require 'rodimus/version'
5
5
 
6
6
  module Rodimus
7
+ $SAFE = 1 # Because we're using DRb
8
+
7
9
  class << self
8
10
  attr_accessor :configuration
9
11
  end
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 = StringIO.new
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 = Object.new
18
- step.extend(Rodimus::Step)
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 = Class.new do
28
- include Rodimus::Step
29
-
30
- def process_row(row)
31
- row.upcase
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.0
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-17 00:00:00.000000000 Z
11
+ date: 2014-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler