alephant-publisher 0.2.7 → 0.2.8
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 +1 -1
- data/lib/alephant/publisher/sqs_helper/{archive.rb → archiver.rb} +14 -11
- data/lib/alephant/publisher/sqs_helper/queue.rb +12 -10
- data/lib/alephant/publisher/version.rb +1 -1
- data/spec/archiver_spec.rb +33 -0
- data/spec/queue_spec.rb +30 -0
- metadata +7 -4
- data/lib/alephant/publisher/archive.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02d5dc51f562742f5877b89d5ea015b790a12bd5
|
4
|
+
data.tar.gz: e97f0f2b0940c5e0b655e8d1292795cd73547e8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85eff354a827173958c576f9372bbd3b44daf1f016778a04db3bd0ed2627e8f39d39ab88c75f0e358ff3b3410d44b3cb08ef55e45d65c2a0485a98d8035b0aac
|
7
|
+
data.tar.gz: 0d9ade92068b794ced6147bfcbfb9ae2c948208be1dcf497c41e6a1411d59582c5c2c761a2bfe36ba90c24ae1650d5b0d32acbf4b4710a7aad719d48e13cd637
|
data/lib/alephant/publisher.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative 'env'
|
|
3
3
|
require 'alephant/publisher/version'
|
4
4
|
require 'alephant/publisher/options'
|
5
5
|
require 'alephant/publisher/sqs_helper/queue'
|
6
|
-
require 'alephant/publisher/sqs_helper/
|
6
|
+
require 'alephant/publisher/sqs_helper/archiver'
|
7
7
|
require 'alephant/publisher/writer'
|
8
8
|
require 'alephant/logger'
|
9
9
|
|
@@ -2,27 +2,29 @@ module Alephant
|
|
2
2
|
module Publisher
|
3
3
|
module SQSHelper
|
4
4
|
class Archiver
|
5
|
-
attr_reader :cache
|
5
|
+
attr_reader :cache, :async
|
6
6
|
|
7
|
-
def initialize(cache)
|
7
|
+
def initialize(cache, async = true)
|
8
|
+
@async = async
|
8
9
|
@cache = cache
|
9
10
|
end
|
10
11
|
|
11
12
|
def see(message)
|
12
13
|
return if message.nil?
|
13
|
-
|
14
|
-
message.tap do |m|
|
15
|
-
cache.put(
|
16
|
-
"archive/#{m.id}",
|
17
|
-
m.body,
|
18
|
-
message_meta_for(m)
|
19
|
-
)
|
20
|
-
end
|
14
|
+
message.tap { |m| async ? async_store(m) : store(m) }
|
21
15
|
end
|
22
16
|
|
23
17
|
private
|
24
18
|
|
25
|
-
def
|
19
|
+
def async_store(m)
|
20
|
+
Thread.new { store(m) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def store(m)
|
24
|
+
cache.put("archive/#{m.id}", m.body, meta_for(m))
|
25
|
+
end
|
26
|
+
|
27
|
+
def meta_for(m)
|
26
28
|
{
|
27
29
|
:id => m.id,
|
28
30
|
:md5 => m.md5,
|
@@ -34,3 +36,4 @@ module Alephant
|
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
39
|
+
|
@@ -12,7 +12,7 @@ module Alephant
|
|
12
12
|
|
13
13
|
attr_reader :queue, :timeout, :wait_time, :archiver
|
14
14
|
|
15
|
-
def initialize(queue, archiver, timeout = VISABILITY_TIMEOUT, wait_time = WAIT_TIME)
|
15
|
+
def initialize(queue, archiver = nil, timeout = VISABILITY_TIMEOUT, wait_time = WAIT_TIME)
|
16
16
|
@queue = queue
|
17
17
|
@archiver = archiver
|
18
18
|
@timeout = timeout
|
@@ -22,18 +22,20 @@ module Alephant
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def message
|
25
|
-
recieve.tap
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
recieve.tap { |m| process(m) unless m.nil? }
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def process(m)
|
31
|
+
logger.info("Queue#message: received #{m.id}")
|
32
|
+
archive m
|
31
33
|
end
|
32
34
|
|
33
35
|
def archive(m)
|
34
|
-
unless
|
35
|
-
|
36
|
-
|
36
|
+
archiver.see(m) unless archiver.nil?
|
37
|
+
rescue StandardError => e
|
38
|
+
logger.warn("Queue#archive: archive failed (#{e.message})");
|
37
39
|
end
|
38
40
|
|
39
41
|
def recieve
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alephant::Publisher::SQSHelper::Archiver do
|
4
|
+
describe "#see" do
|
5
|
+
it "calls cache put with the correct params" do
|
6
|
+
time_now = Time.parse("Feb 24 1981")
|
7
|
+
Time.stub!(:now).and_return(time_now)
|
8
|
+
|
9
|
+
q = double("queue").as_null_object
|
10
|
+
c = double("cache").as_null_object
|
11
|
+
|
12
|
+
expect(q).to receive(:url).and_return('url')
|
13
|
+
|
14
|
+
m = Struct.new(:id, :body, :md5, :queue).new('id', 'body', 'md5', q)
|
15
|
+
|
16
|
+
expect(c).to receive(:put).with(
|
17
|
+
"archive/id",
|
18
|
+
"body",
|
19
|
+
{
|
20
|
+
:id => "id",
|
21
|
+
:md5 => "md5",
|
22
|
+
:logged_at => time_now.to_s,
|
23
|
+
:queue => "url"
|
24
|
+
}
|
25
|
+
)
|
26
|
+
|
27
|
+
instance = Alephant::Publisher::SQSHelper::Archiver.new(c, false)
|
28
|
+
|
29
|
+
instance.see(m)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/spec/queue_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Alephant::Publisher::SQSHelper::Queue do
|
4
|
+
describe "#message" do
|
5
|
+
it "returns a message" do
|
6
|
+
m = double("message").as_null_object
|
7
|
+
q = double("queue").as_null_object
|
8
|
+
|
9
|
+
expect(q).to receive(:receive_message).and_return(m)
|
10
|
+
|
11
|
+
instance = Alephant::Publisher::SQSHelper::Queue.new(q)
|
12
|
+
|
13
|
+
expect(instance.message).to eq(m)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "call see(m) on the handed archiver" do
|
17
|
+
a = double("archiver").as_null_object
|
18
|
+
m = double("message").as_null_object
|
19
|
+
q = double("queue").as_null_object
|
20
|
+
|
21
|
+
expect(q).to receive(:receive_message).and_return(m)
|
22
|
+
expect(a).to receive(:see).with(m)
|
23
|
+
|
24
|
+
instance = Alephant::Publisher::SQSHelper::Queue.new(q, a)
|
25
|
+
|
26
|
+
expect(instance.message).to eq(m)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Integralist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -363,18 +363,19 @@ files:
|
|
363
363
|
- alephant-publisher.gemspec
|
364
364
|
- lib/alephant/env.rb
|
365
365
|
- lib/alephant/publisher.rb
|
366
|
-
- lib/alephant/publisher/archive.rb
|
367
366
|
- lib/alephant/publisher/options.rb
|
368
367
|
- lib/alephant/publisher/render_mapper.rb
|
369
|
-
- lib/alephant/publisher/sqs_helper/
|
368
|
+
- lib/alephant/publisher/sqs_helper/archiver.rb
|
370
369
|
- lib/alephant/publisher/sqs_helper/queue.rb
|
371
370
|
- lib/alephant/publisher/version.rb
|
372
371
|
- lib/alephant/publisher/writer.rb
|
372
|
+
- spec/archiver_spec.rb
|
373
373
|
- spec/fixtures/components/foo/models/bar.rb
|
374
374
|
- spec/fixtures/components/foo/models/foo.rb
|
375
375
|
- spec/fixtures/components/foo/templates/bar.mustache
|
376
376
|
- spec/fixtures/components/foo/templates/foo.mustache
|
377
377
|
- spec/publisher_spec.rb
|
378
|
+
- spec/queue_spec.rb
|
378
379
|
- spec/render_mapper_spec.rb
|
379
380
|
- spec/spec_helper.rb
|
380
381
|
- spec/writer_spec.rb
|
@@ -403,11 +404,13 @@ signing_key:
|
|
403
404
|
specification_version: 4
|
404
405
|
summary: Static publishing to S3 based on SQS messages
|
405
406
|
test_files:
|
407
|
+
- spec/archiver_spec.rb
|
406
408
|
- spec/fixtures/components/foo/models/bar.rb
|
407
409
|
- spec/fixtures/components/foo/models/foo.rb
|
408
410
|
- spec/fixtures/components/foo/templates/bar.mustache
|
409
411
|
- spec/fixtures/components/foo/templates/foo.mustache
|
410
412
|
- spec/publisher_spec.rb
|
413
|
+
- spec/queue_spec.rb
|
411
414
|
- spec/render_mapper_spec.rb
|
412
415
|
- spec/spec_helper.rb
|
413
416
|
- spec/writer_spec.rb
|