alephant-publisher 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -0
- data/lib/alephant/publisher.rb +6 -17
- data/lib/alephant/publisher/options.rb +59 -0
- data/lib/alephant/publisher/version.rb +1 -1
- data/spec/publisher_spec.rb +3 -3
- data/spec/writer_spec.rb +7 -7
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bacfbe3bd9b3fa1e06d05b6c1041e7e30d7c6e64
|
4
|
+
data.tar.gz: b58a5689a5a9f4028f6ac4c565801bc83ef18203
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fecb4254a1c8bd0cb72ea7e3b01f1ba3641b9dabc6ffc4c6fb90ed6066dca1df1504cb991c5fe454c015a1fdec5c7cd137201eeafa7cb2caf7c132b0916b8673
|
7
|
+
data.tar.gz: 09be2c0a1557a66538b2f83f46a4dc0069d99ca2898be8960c42bdaa74d36d22cf8d63d7f83be914f20c2107bdc3028bb8dabd8c7f3fbc20255dddc43e2a12b4
|
data/README.md
CHANGED
@@ -67,6 +67,47 @@ thread = Alephant::Alephant.new(opts, logger).run!
|
|
67
67
|
thread.join
|
68
68
|
```
|
69
69
|
|
70
|
+
Publisher requires both queue options and writer options to be provided. To ensure a standard format you should use the `Options` class to generate your options before passing them onto the Publisher...
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
opts = Alephant::Publisher::Options.new
|
74
|
+
# => #<Alephant::Publisher::Options:0x0602f958 @queue={}, @writer={}>
|
75
|
+
|
76
|
+
opts.queue
|
77
|
+
# => {}
|
78
|
+
# empty to start with
|
79
|
+
|
80
|
+
opts.writer
|
81
|
+
# => {}
|
82
|
+
# empty to start with
|
83
|
+
|
84
|
+
opts.add_queue(:foo => "bar")
|
85
|
+
# The key 'foo' is invalid
|
86
|
+
# => nil
|
87
|
+
|
88
|
+
opts.queue
|
89
|
+
# => {}
|
90
|
+
# still empty as the foo key was invalid
|
91
|
+
|
92
|
+
opts.add_queue(:sqs_queue_url => "bar")
|
93
|
+
# => {:sqs_queue_url=>"bar"}
|
94
|
+
|
95
|
+
opts.queue
|
96
|
+
# => {:sqs_queue_url=>"bar"}
|
97
|
+
|
98
|
+
opts.add_writer(:sqs_queue_url => "bar")
|
99
|
+
# The key 'sqs_queue_url' is invalid
|
100
|
+
# => nil
|
101
|
+
# the sqs_queue_url key was valid for the queue options,
|
102
|
+
# but is invalid when trying to add it to the writer options
|
103
|
+
|
104
|
+
opts.add_writer(:msg_vary_id_path => "bar")
|
105
|
+
=> {:msg_vary_id_path=>"bar"}
|
106
|
+
|
107
|
+
opts.writer
|
108
|
+
=> {:msg_vary_id_path=>"bar"}
|
109
|
+
```
|
110
|
+
|
70
111
|
logger is optional, and must confirm to the Ruby standard logger interface
|
71
112
|
|
72
113
|
Provide a view in a folder (fixtures are optional):
|
data/lib/alephant/publisher.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative 'env'
|
2
2
|
|
3
3
|
require 'alephant/publisher/version'
|
4
|
+
require 'alephant/publisher/options'
|
4
5
|
require 'alephant/publisher/queue'
|
5
6
|
require 'alephant/publisher/writer'
|
6
7
|
require 'alephant/logger'
|
@@ -23,24 +24,12 @@ module Alephant
|
|
23
24
|
::Alephant::Logger.set_logger(logger) unless logger.nil?
|
24
25
|
|
25
26
|
@opts = opts
|
27
|
+
|
26
28
|
@queue = Queue.new(
|
27
|
-
opts[:sqs_queue_url],
|
28
|
-
opts[:visibility_timeout] || VISIBILITY_TIMEOUT,
|
29
|
-
opts[:receive_wait_time] || RECEIVE_WAIT_TIME,
|
29
|
+
opts.queue[:sqs_queue_url],
|
30
|
+
opts.queue[:visibility_timeout] || VISIBILITY_TIMEOUT,
|
31
|
+
opts.queue[:receive_wait_time] || RECEIVE_WAIT_TIME,
|
30
32
|
)
|
31
|
-
|
32
|
-
@writer_opts = opts.select do |k,v|
|
33
|
-
[
|
34
|
-
:msg_vary_id_path,
|
35
|
-
:sequencer_table_name,
|
36
|
-
:sequence_id_path,
|
37
|
-
:renderer_id,
|
38
|
-
:s3_bucket_id,
|
39
|
-
:s3_object_path,
|
40
|
-
:view_path,
|
41
|
-
:lookup_table_name
|
42
|
-
].include? k
|
43
|
-
end
|
44
33
|
end
|
45
34
|
|
46
35
|
def run!
|
@@ -51,7 +40,7 @@ module Alephant
|
|
51
40
|
|
52
41
|
def process(msg)
|
53
42
|
unless msg.nil?
|
54
|
-
Writer.new(@
|
43
|
+
Writer.new(@opts.writer, msg).run!
|
55
44
|
msg.delete
|
56
45
|
end
|
57
46
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'alephant/logger'
|
3
|
+
|
4
|
+
module Alephant
|
5
|
+
module Publisher
|
6
|
+
class InvalidKeySpecifiedError < StandardError; end
|
7
|
+
|
8
|
+
class Options
|
9
|
+
attr_reader :queue, :writer
|
10
|
+
|
11
|
+
QUEUE_OPTS = [
|
12
|
+
:receive_wait_time,
|
13
|
+
:sqs_queue_url,
|
14
|
+
:visibility_timeout
|
15
|
+
]
|
16
|
+
|
17
|
+
WRITER_OPTS = [
|
18
|
+
:lookup_table_name,
|
19
|
+
:msg_vary_id_path,
|
20
|
+
:renderer_id,
|
21
|
+
:s3_bucket_id,
|
22
|
+
:s3_object_path,
|
23
|
+
:sequence_id_path,
|
24
|
+
:sequencer_table_name,
|
25
|
+
:view_path
|
26
|
+
]
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@queue = {}
|
30
|
+
@writer = {}
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_queue(opts)
|
34
|
+
execute @queue, QUEUE_OPTS, opts
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_writer(opts)
|
38
|
+
execute @writer, WRITER_OPTS, opts
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def execute(instance, type, opts)
|
44
|
+
begin
|
45
|
+
validate type, opts
|
46
|
+
instance.merge! opts
|
47
|
+
rescue Exception => e
|
48
|
+
puts e.message
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate(type, opts)
|
53
|
+
opts.each do |key, value|
|
54
|
+
raise InvalidKeySpecifiedError, "The key '#{key}' is invalid" unless type.include? key.to_sym
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/publisher_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Alephant::Publisher do
|
4
|
-
let(:
|
4
|
+
let(:options) { Alephant::Publisher::Options.new }
|
5
|
+
let(:instance) { Alephant::Publisher.create(options) }
|
5
6
|
|
6
7
|
before(:each) do
|
7
8
|
Alephant::Publisher::Queue.any_instance.stub(:initialize)
|
@@ -9,8 +10,7 @@ describe Alephant::Publisher do
|
|
9
10
|
|
10
11
|
describe "#initialize(opts = {}, logger)" do
|
11
12
|
it "sets parser, sequencer, queue and writer" do
|
12
|
-
expect(instance.queue).to
|
13
|
+
expect(instance.queue).to be_a Alephant::Publisher::Queue
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
16
|
-
|
data/spec/writer_spec.rb
CHANGED
@@ -3,14 +3,14 @@ require 'spec_helper'
|
|
3
3
|
describe Alephant::Publisher::Writer do
|
4
4
|
let(:opts) do
|
5
5
|
{
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:renderer_id
|
9
|
-
:
|
10
|
-
:
|
6
|
+
:lookup_table_name => 'lookup_table_name',
|
7
|
+
:msg_vary_id_path => '$.vary',
|
8
|
+
:renderer_id => :renderer_id,
|
9
|
+
:s3_bucket_id => :s3_bucket_id,
|
10
|
+
:s3_object_path => :s3_object_path,
|
11
|
+
:sequence_id_path => '$.sequence',
|
11
12
|
:sequencer_table_name => :sequencer_table_name,
|
12
|
-
:
|
13
|
-
:msg_vary_id_path => '$.vary',
|
13
|
+
:view_path => :view_path
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Integralist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -363,6 +363,7 @@ files:
|
|
363
363
|
- alephant-publisher.gemspec
|
364
364
|
- lib/alephant/env.rb
|
365
365
|
- lib/alephant/publisher.rb
|
366
|
+
- lib/alephant/publisher/options.rb
|
366
367
|
- lib/alephant/publisher/queue.rb
|
367
368
|
- lib/alephant/publisher/render_mapper.rb
|
368
369
|
- lib/alephant/publisher/version.rb
|
@@ -410,3 +411,4 @@ test_files:
|
|
410
411
|
- spec/render_mapper_spec.rb
|
411
412
|
- spec/spec_helper.rb
|
412
413
|
- spec/writer_spec.rb
|
414
|
+
has_rdoc:
|