alephant-publisher 0.4.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 795840e6b9cfa9d30907a40484d6282382b306bd
4
- data.tar.gz: 9f1756bb8152c8c7b5e2f8e0fab13feaa68a0e11
3
+ metadata.gz: 416819c915a77f629cd132dcfe5ec000c24597c9
4
+ data.tar.gz: 707c3e99c0f4fc73e24714833b984d3d6b81ae57
5
5
  SHA512:
6
- metadata.gz: 43ab86d14c9d7c9aff420aeb29f2cdc55ba9310bd937d86a2c2932b119df5f3cd505d975462aaf03f2c8e62a72d3c85dd9dde8a9db2570120464c2f8d0401b20
7
- data.tar.gz: e643a752be72292c2be71cec025da3d4599361dcf281fe4bc4cc9b3fa49f6f8c026b1a71e02f4656fc0fed429cb63de53485a7fc4595a935ed8cf4f7288f223d
6
+ metadata.gz: f7f94b6a01043793aee3530fe0ad281a810422eda3d4c2d27400f911849dd2af93736c4030da62db737697abc5d82dafc778d37df1ee06e4349e36dbfd0e7015
7
+ data.tar.gz: a3330937710ab1b655704d295df19e1971384aa1e22e5932383a97dd45dfcce59b65a6e784b04276d4a8b305abec381eb3103bdb29c573f07809165f0726cea1
@@ -4,27 +4,29 @@ require 'alephant/publisher/version'
4
4
  require 'alephant/publisher/options'
5
5
  require 'alephant/publisher/sqs_helper/queue'
6
6
  require 'alephant/publisher/sqs_helper/archiver'
7
- require 'alephant/publisher/writer'
8
7
  require 'alephant/logger'
9
8
  require 'alephant/support/aop'
9
+ require 'alephant/publisher/processor'
10
10
 
11
11
  module Alephant
12
12
  module Publisher
13
13
  include Logger
14
14
  extend Alephant::Support::AOP
15
15
 
16
- def self.create(opts = {})
17
- Publisher.new(opts)
16
+ def self.create(opts = {}, processor = nil)
17
+ processor ||= Processor.new(opts.writer)
18
+ Publisher.new(opts, processor)
18
19
  end
19
20
 
20
21
  class Publisher
21
22
  VISIBILITY_TIMEOUT = 60
22
23
  RECEIVE_WAIT_TIME = 15
23
24
 
24
- attr_reader :queue, :executor, :opts
25
+ attr_reader :queue, :executor, :opts, :processor
25
26
 
26
- def initialize(opts)
27
+ def initialize(opts, processor = nil)
27
28
  @opts = opts
29
+ @processor = processor
28
30
 
29
31
  @queue = SQSHelper::Queue.new(
30
32
  aws_queue,
@@ -35,7 +37,7 @@ module Alephant
35
37
  end
36
38
 
37
39
  def run!
38
- loop { process(@queue.message) }
40
+ loop { processor.consume(@queue.message) }
39
41
  end
40
42
 
41
43
  private
@@ -55,17 +57,6 @@ module Alephant
55
57
  AWS::SQS.new.queues[opts.queue[:sqs_queue_url]]
56
58
  end
57
59
 
58
- def write(msg)
59
- Writer.new(opts.writer, msg).run!
60
- end
61
-
62
- def process(msg)
63
- unless msg.nil?
64
- write msg
65
- msg.delete
66
- end
67
- end
68
-
69
60
  end
70
61
  end
71
62
  end
@@ -0,0 +1,26 @@
1
+ require 'alephant/publisher/writer'
2
+ require 'alephant/publisher/processor/base'
3
+
4
+ module Alephant
5
+ module Publisher
6
+ class Processor < BaseProcessor
7
+ attr_reader :writer_config
8
+
9
+ def initialize(writer_config = {})
10
+ @writer_config = writer_config
11
+ end
12
+
13
+ def consume(msg)
14
+ unless msg.nil?
15
+ write msg
16
+ msg.delete
17
+ end
18
+ end
19
+
20
+ def write(msg)
21
+ Writer.new(writer_config, msg).run!
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ module Alephant
2
+ module Publisher
3
+ class BaseProcessor
4
+
5
+ def consume(msg)
6
+ raise NotImplementedError.new("You must implement the #consume(msg) method")
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Publisher
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Alephant::Publisher::Processor do
4
+
5
+ before(:each) do
6
+ Alephant::Publisher::Writer.any_instance.stub(:initialize)
7
+ Alephant::Publisher::Writer.any_instance.stub(:run!)
8
+ end
9
+
10
+ describe "#consume(msg)" do
11
+ it "Consume the message and deletes it" do
12
+
13
+ msg = double('AWS::SQS::ReceivedMessage', :delete => nil)
14
+ expect(msg).to receive(:delete)
15
+ subject.consume(msg)
16
+
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Integralist
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-16 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -364,6 +364,8 @@ files:
364
364
  - lib/alephant/env.rb
365
365
  - lib/alephant/publisher.rb
366
366
  - lib/alephant/publisher/options.rb
367
+ - lib/alephant/publisher/processor.rb
368
+ - lib/alephant/publisher/processor/base.rb
367
369
  - lib/alephant/publisher/render_mapper.rb
368
370
  - lib/alephant/publisher/sqs_helper/archiver.rb
369
371
  - lib/alephant/publisher/sqs_helper/queue.rb
@@ -374,6 +376,7 @@ files:
374
376
  - spec/fixtures/components/foo/models/foo.rb
375
377
  - spec/fixtures/components/foo/templates/bar.mustache
376
378
  - spec/fixtures/components/foo/templates/foo.mustache
379
+ - spec/processor_spec.rb
377
380
  - spec/publisher_spec.rb
378
381
  - spec/queue_spec.rb
379
382
  - spec/render_mapper_spec.rb
@@ -409,6 +412,7 @@ test_files:
409
412
  - spec/fixtures/components/foo/models/foo.rb
410
413
  - spec/fixtures/components/foo/templates/bar.mustache
411
414
  - spec/fixtures/components/foo/templates/foo.mustache
415
+ - spec/processor_spec.rb
412
416
  - spec/publisher_spec.rb
413
417
  - spec/queue_spec.rb
414
418
  - spec/render_mapper_spec.rb