alephant-publisher 0.1.4 → 0.1.5
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/alephant-publisher.gemspec +1 -0
- data/lib/alephant/publisher.rb +5 -2
- data/lib/alephant/publisher/publish_task.rb +1 -1
- data/lib/alephant/publisher/version.rb +1 -1
- data/lib/alephant/publisher/writer.rb +73 -40
- data/spec/queue_spec.rb +0 -22
- data/spec/spec_helper.rb +0 -5
- data/spec/writer_spec.rb +10 -8
- metadata +17 -3
- data/lib/alephant/publisher/write_operation.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c8298673d27ca51e22d1ff4e124bf838b91de45
|
4
|
+
data.tar.gz: 554f9a1eb1dd64e4f43b42418dc5494c67dae3fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d36ef84078d02c36ce4b6fc2ddb665aff51a622ef9593ed3ae64faef783fb9603a7f602bbb557faddeb898d6089df492f9cd3e20ec06229058a639e31f36cf9
|
7
|
+
data.tar.gz: eb6f7446bb0abe43b1ba0c5088b543733e1b44de6c9187bca159e0afb54c893015d6c53b0018ac64c772adc2ef49140abea319d13c8cd6ccb72cf289911e91ba
|
data/alephant-publisher.gemspec
CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_runtime_dependency 'mustache', '>= 0.99.5'
|
36
36
|
spec.add_runtime_dependency 'jsonpath'
|
37
37
|
spec.add_runtime_dependency 'crimp'
|
38
|
+
spec.add_runtime_dependency 'peach'
|
38
39
|
spec.add_runtime_dependency 'alephant-support'
|
39
40
|
spec.add_runtime_dependency 'alephant-sequencer'
|
40
41
|
spec.add_runtime_dependency 'alephant-cache'
|
data/lib/alephant/publisher.rb
CHANGED
@@ -22,11 +22,12 @@ module Alephant
|
|
22
22
|
|
23
23
|
class Publisher
|
24
24
|
|
25
|
-
VISIBILITY_TIMEOUT =
|
26
|
-
KEEP_ALIVE_TIMEOUT =
|
25
|
+
VISIBILITY_TIMEOUT = 60
|
26
|
+
KEEP_ALIVE_TIMEOUT = 60
|
27
27
|
RECEIVE_WAIT_TIME = 15
|
28
28
|
POOL_MIN_SIZE = 2
|
29
29
|
POOL_MAX_SIZE = 4
|
30
|
+
QUEUE_THROTTLE = 0.5
|
30
31
|
|
31
32
|
attr_reader :queue, :executor
|
32
33
|
|
@@ -72,6 +73,8 @@ module Alephant
|
|
72
73
|
)
|
73
74
|
)
|
74
75
|
)
|
76
|
+
|
77
|
+
sleep QUEUE_THROTTLE while executor.getActiveCount == executor.getMaximumPoolSize
|
75
78
|
end
|
76
79
|
|
77
80
|
executor.shutdown()
|
@@ -1,77 +1,110 @@
|
|
1
|
+
require 'peach'
|
2
|
+
require 'crimp'
|
3
|
+
|
1
4
|
require 'alephant/cache'
|
2
5
|
require 'alephant/views'
|
3
6
|
require 'alephant/renderer'
|
4
7
|
require 'alephant/lookup'
|
5
|
-
|
6
|
-
require 'alephant/
|
8
|
+
require 'alephant/logger'
|
9
|
+
require 'alephant/sequencer'
|
10
|
+
require 'alephant/support/parser'
|
7
11
|
require 'alephant/publisher/render_mapper'
|
8
12
|
|
9
13
|
module Alephant
|
10
14
|
module Publisher
|
11
15
|
class Writer
|
12
|
-
|
16
|
+
include ::Alephant::Logger
|
17
|
+
attr_reader :config, :message, :cache, :parser, :mapper
|
18
|
+
|
19
|
+
def initialize(config, message)
|
20
|
+
@config = config
|
21
|
+
@message = message
|
13
22
|
|
14
|
-
def initialize(opts)
|
15
23
|
@cache = Cache.new(
|
16
|
-
|
17
|
-
|
24
|
+
config[:s3_bucket_id],
|
25
|
+
config[:s3_object_path]
|
26
|
+
)
|
27
|
+
|
28
|
+
@parser = Support::Parser.new(
|
29
|
+
config[:msg_vary_id_path]
|
18
30
|
)
|
19
31
|
|
20
32
|
@mapper = RenderMapper.new(
|
21
|
-
|
22
|
-
|
33
|
+
config[:renderer_id],
|
34
|
+
config[:view_path]
|
23
35
|
)
|
36
|
+
end
|
24
37
|
|
25
|
-
|
38
|
+
def run!
|
39
|
+
batch? ? batch.sequence(message, &perform) : perform.call
|
40
|
+
end
|
26
41
|
|
27
|
-
|
42
|
+
private
|
28
43
|
|
29
|
-
|
30
|
-
|
31
|
-
:table_name => opts[:sequencer_table_name],
|
32
|
-
:id_path => opts[:sequence_id_path]
|
33
|
-
},
|
34
|
-
:msg_vary_path => opts[:msg_vary_id_path],
|
35
|
-
:renderer_id => opts[:renderer_id]
|
36
|
-
}
|
44
|
+
def perform
|
45
|
+
Proc.new { renders.peach { |id, r| write(id, r) } }
|
37
46
|
end
|
38
47
|
|
39
|
-
def write(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
mapper.generate(write_op.data).each do |component_id, renderer|
|
44
|
-
write_component(write_op, component_id, renderer)
|
48
|
+
def write(id, r)
|
49
|
+
begin
|
50
|
+
seq_for(id).sequence(message) do
|
51
|
+
store(id, r.render, location_for(id))
|
45
52
|
end
|
53
|
+
rescue Exception => e
|
54
|
+
logger.warn "Alephant::Publisher::Writer#write: #{e.message}\n#{e.backtrace.join('\n')}"
|
55
|
+
|
56
|
+
raise e
|
46
57
|
end
|
47
58
|
end
|
48
59
|
|
49
|
-
|
60
|
+
def store(id, content, location)
|
61
|
+
cache.put(location, content)
|
62
|
+
lookup.write(id, options, seq_id, location)
|
63
|
+
end
|
50
64
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
65
|
+
def location_for(id)
|
66
|
+
"#{config[:renderer_id]}/#{id}/#{opt_hash}/#{seq_id}"
|
67
|
+
end
|
54
68
|
|
55
|
-
|
56
|
-
|
57
|
-
end
|
69
|
+
def batch
|
70
|
+
@batch ||= (renders.count > 1) ? seq_for(config[:renderer_id]) : nil
|
58
71
|
end
|
59
72
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
73
|
+
def batch?
|
74
|
+
!batch.nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
def seq_for(id)
|
78
|
+
Sequencer.create(config[:sequencer_table_name], seq_key_from(id), config[:sequence_id_path])
|
63
79
|
end
|
64
80
|
|
65
|
-
def
|
66
|
-
|
81
|
+
def seq_key_from(id)
|
82
|
+
"#{id}/#{opt_hash}"
|
67
83
|
end
|
68
84
|
|
69
|
-
def
|
70
|
-
|
71
|
-
base_name = "#{@renderer_id}/#{component_id}/#{options_hash}"
|
72
|
-
version ? "#{base_name}/#{version}" : base_name
|
85
|
+
def seq_id
|
86
|
+
@seq_id ||= Sequencer::Sequencer.sequence_id_from(message, config[:sequence_id_path])
|
73
87
|
end
|
74
88
|
|
89
|
+
def renders
|
90
|
+
@renders ||= mapper.generate(data)
|
91
|
+
end
|
92
|
+
|
93
|
+
def opt_hash
|
94
|
+
@opt_hash ||= Crimp.signature(options)
|
95
|
+
end
|
96
|
+
|
97
|
+
def options
|
98
|
+
@options ||= data[:options]
|
99
|
+
end
|
100
|
+
|
101
|
+
def data
|
102
|
+
@data ||= parser.parse(message)
|
103
|
+
end
|
104
|
+
|
105
|
+
def lookup
|
106
|
+
Lookup.create(config[:lookup_table_name])
|
107
|
+
end
|
75
108
|
end
|
76
109
|
end
|
77
110
|
end
|
data/spec/queue_spec.rb
CHANGED
@@ -42,28 +42,6 @@ describe Alephant::Publisher::Queue do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
describe "poll(*args, &block)" do
|
46
|
-
it "calls @q.poll(*args, &block)" do
|
47
|
-
block = double()
|
48
|
-
block.should_receive(:called)
|
49
|
-
|
50
|
-
AWS::SQS::Queue
|
51
|
-
.any_instance
|
52
|
-
.stub(:exists?)
|
53
|
-
.and_return(true)
|
54
|
-
|
55
|
-
AWS::SQS::Queue
|
56
|
-
.any_instance
|
57
|
-
.should_receive(:poll)
|
58
|
-
.with(:arg)
|
59
|
-
.and_yield
|
60
|
-
|
61
|
-
subject.new(:id).poll(:arg) do
|
62
|
-
block.called
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
45
|
describe "sleep_until_queue_exists" do
|
68
46
|
context "@q.exists? == true" do
|
69
47
|
it "should not call sleep" do
|
data/spec/spec_helper.rb
CHANGED
@@ -2,9 +2,4 @@ require 'pry'
|
|
2
2
|
|
3
3
|
require 'aws-sdk'
|
4
4
|
require 'alephant/publisher'
|
5
|
-
require 'alephant/publisher/models/writer'
|
6
|
-
require 'alephant/publisher/models/queue'
|
7
|
-
require 'alephant/publisher/models/render_mapper'
|
8
|
-
require 'alephant/renderer'
|
9
|
-
require 'alephant/support/parser'
|
10
5
|
|
data/spec/writer_spec.rb
CHANGED
@@ -50,9 +50,9 @@ describe Alephant::Publisher::Writer do
|
|
50
50
|
.any_instance
|
51
51
|
.stub(:get_last_seen)
|
52
52
|
|
53
|
-
Alephant::Lookup::
|
53
|
+
Alephant::Lookup::LookupTable
|
54
54
|
.any_instance
|
55
|
-
.stub(:
|
55
|
+
.stub(:create)
|
56
56
|
|
57
57
|
Alephant::Lookup::LookupTable
|
58
58
|
.any_instance
|
@@ -67,11 +67,7 @@ describe Alephant::Publisher::Writer do
|
|
67
67
|
|
68
68
|
end
|
69
69
|
|
70
|
-
|
71
|
-
Alephant::Publisher::Writer.new(opts)
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "#write(data, version)" do
|
70
|
+
describe "#run!" do
|
75
71
|
let(:msg) do
|
76
72
|
data = {
|
77
73
|
"sequence" => "1",
|
@@ -84,6 +80,10 @@ describe Alephant::Publisher::Writer do
|
|
84
80
|
'renderer_id/component_id/218c835cec343537589dbf1619532e4d/1'
|
85
81
|
end
|
86
82
|
|
83
|
+
subject do
|
84
|
+
Alephant::Publisher::Writer.new(opts, msg)
|
85
|
+
end
|
86
|
+
|
87
87
|
it "should write the correct lookup location" do
|
88
88
|
Alephant::Cache.any_instance.stub(:put)
|
89
89
|
|
@@ -91,7 +91,9 @@ describe Alephant::Publisher::Writer do
|
|
91
91
|
.any_instance
|
92
92
|
.should_receive(:write)
|
93
93
|
.with(
|
94
|
+
"component_id",
|
94
95
|
{:variant=>"foo"},
|
96
|
+
1,
|
95
97
|
expected_location
|
96
98
|
)
|
97
99
|
end
|
@@ -106,7 +108,7 @@ describe Alephant::Publisher::Writer do
|
|
106
108
|
end
|
107
109
|
|
108
110
|
after do
|
109
|
-
subject.
|
111
|
+
subject.run!
|
110
112
|
end
|
111
113
|
end
|
112
114
|
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Integralist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -234,6 +234,20 @@ dependencies:
|
|
234
234
|
version: '0'
|
235
235
|
prerelease: false
|
236
236
|
type: :runtime
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: peach
|
239
|
+
version_requirements: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - '>='
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
requirement: !ruby/object:Gem::Requirement
|
245
|
+
requirements:
|
246
|
+
- - '>='
|
247
|
+
- !ruby/object:Gem::Version
|
248
|
+
version: '0'
|
249
|
+
prerelease: false
|
250
|
+
type: :runtime
|
237
251
|
- !ruby/object:Gem::Dependency
|
238
252
|
name: alephant-support
|
239
253
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -353,7 +367,6 @@ files:
|
|
353
367
|
- lib/alephant/publisher/queue.rb
|
354
368
|
- lib/alephant/publisher/render_mapper.rb
|
355
369
|
- lib/alephant/publisher/version.rb
|
356
|
-
- lib/alephant/publisher/write_operation.rb
|
357
370
|
- lib/alephant/publisher/writer.rb
|
358
371
|
- spec/fixtures/components/foo/models/bar.rb
|
359
372
|
- spec/fixtures/components/foo/models/foo.rb
|
@@ -398,3 +411,4 @@ test_files:
|
|
398
411
|
- spec/render_mapper_spec.rb
|
399
412
|
- spec/spec_helper.rb
|
400
413
|
- spec/writer_spec.rb
|
414
|
+
has_rdoc:
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'crimp'
|
2
|
-
|
3
|
-
require 'alephant/sequencer'
|
4
|
-
require 'alephant/support/parser'
|
5
|
-
|
6
|
-
module Alephant
|
7
|
-
module Publisher
|
8
|
-
class WriteOperation
|
9
|
-
attr_reader :msg, :data, :options, :options_hash, :version, :batch_sequencer
|
10
|
-
|
11
|
-
def initialize(msg, opts)
|
12
|
-
@msg = msg
|
13
|
-
@data = Support::Parser.new(opts[:msg_vary_path]).parse(msg)
|
14
|
-
@options = @data[:options]
|
15
|
-
@options_hash = Crimp.signature(@options)
|
16
|
-
@renderer_id = opts[:renderer_id]
|
17
|
-
@sequencer_opts = opts[:sequencer_opts]
|
18
|
-
@batch_sequencer = sequencer_for(@renderer_id, @options)
|
19
|
-
@version = @batch_sequencer.sequence_id_from(msg)
|
20
|
-
end
|
21
|
-
|
22
|
-
def sequencer_for(id, options)
|
23
|
-
Sequencer.create(
|
24
|
-
@sequencer_opts[:table_name],
|
25
|
-
sequencer_id_from(id, options),
|
26
|
-
@sequencer_opts[:id_path]
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def sequencer_id_from(id,options)
|
33
|
-
"#{id}/#{Crimp.signature(options)}"
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|