alephant-publisher 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alephant/publisher.rb +8 -17
- data/lib/alephant/publisher/processor.rb +26 -0
- data/lib/alephant/publisher/processor/base.rb +11 -0
- data/lib/alephant/publisher/version.rb +1 -1
- data/spec/processor_spec.rb +19 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 416819c915a77f629cd132dcfe5ec000c24597c9
|
4
|
+
data.tar.gz: 707c3e99c0f4fc73e24714833b984d3d6b81ae57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7f94b6a01043793aee3530fe0ad281a810422eda3d4c2d27400f911849dd2af93736c4030da62db737697abc5d82dafc778d37df1ee06e4349e36dbfd0e7015
|
7
|
+
data.tar.gz: a3330937710ab1b655704d295df19e1971384aa1e22e5932383a97dd45dfcce59b65a6e784b04276d4a8b305abec381eb3103bdb29c573f07809165f0726cea1
|
data/lib/alephant/publisher.rb
CHANGED
@@ -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
|
-
|
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 {
|
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,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
|
+
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-
|
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
|