alephant-publisher 0.2.7 → 0.2.8

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: 8c0322caf2f9ce63529630db3c3c8cf22ec57f66
4
- data.tar.gz: 9837cd40f3b09c2742f36957baf4fee31804021a
3
+ metadata.gz: 02d5dc51f562742f5877b89d5ea015b790a12bd5
4
+ data.tar.gz: e97f0f2b0940c5e0b655e8d1292795cd73547e8e
5
5
  SHA512:
6
- metadata.gz: 720c364edee44aa12105ab08308e380931a0ccd2baa3d062389168f40fc78817b49e290d5a9dcf70e33be436d6f69fbf6b7505b1733876665e4cf86eecfbe0e6
7
- data.tar.gz: c544222548e718464c154b2f7fce8fe6d8bf1ff924bd621b2d7713ea2e3aa0360f3467d520cf737358870f8e05f4163667b72efe7c5b85aec401ef7df9c6b988
6
+ metadata.gz: 85eff354a827173958c576f9372bbd3b44daf1f016778a04db3bd0ed2627e8f39d39ab88c75f0e358ff3b3410d44b3cb08ef55e45d65c2a0485a98d8035b0aac
7
+ data.tar.gz: 0d9ade92068b794ced6147bfcbfb9ae2c948208be1dcf497c41e6a1411d59582c5c2c761a2bfe36ba90c24ae1650d5b0d32acbf4b4710a7aad719d48e13cd637
@@ -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/archive'
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 message_meta_for(m)
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 do |m|
26
- unless m.nil?
27
- logger.info("Queue#message: received #{m.id}")
28
- archive m
29
- end
30
- end
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 m.nil?
35
- archiver.see(m)
36
- end
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
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Publisher
3
- VERSION = "0.2.7"
3
+ VERSION = "0.2.8"
4
4
  end
5
5
  end
@@ -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
+
@@ -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.7
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-14 00:00:00.000000000 Z
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/archive.rb
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
@@ -1,19 +0,0 @@
1
- module Alephant
2
- module Publisher
3
- module SQSHelper
4
- class Archiver
5
- attr_reader :cache
6
-
7
- def initialize(cache)
8
- @cache = cache
9
- end
10
-
11
- def see(m)
12
-
13
- m
14
- end
15
-
16
- end
17
- end
18
- end
19
- end