emque-producing 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7696c08ea749cf14c85f0ce963fc626038baa140
4
- data.tar.gz: ea30e9981cb33b17abf705ee85a9d37a946a4180
3
+ metadata.gz: aebb4228bc88f76f459602c76fb168366a837f35
4
+ data.tar.gz: 1d103b5040d76049b86e427889f84a90fcc47a5b
5
5
  SHA512:
6
- metadata.gz: d3132e5cbce4b9c1fec5a428e5d7d202e6d56fa4e7f03946df231e9a73435713f49acf1d4a7de07aea1cc27fb8dc64ed58b907d65f76aa3ceb6c184789a26247
7
- data.tar.gz: 3025a044fd1d2ed21200b3d8aa093bc8b340dd6637dd42b7c5ccc6cb86c60489c6ec3ec03a65a2c95d81445f004ba5f221090420ae16daf4d7c964c2ac81c48d
6
+ metadata.gz: 5e044a178cf2a427db36dc1629cd863220a05cdaf424bda1b34aa5e4661f6e946203aa698663788a15f0fee7da7fb71c85aefde0a86d9f37b4da0ae02c38058a
7
+ data.tar.gz: 067b91871131b82ff47cfe9079c03012b6282c9e0ef3d11f923ca4dc25d3df18a2827fac9a042712ae71413eb7ac1d9e16715242331fea15306438a86941951c
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "rspec", "~> 3.2.0"
30
30
  spec.add_development_dependency "pry"
31
31
  spec.add_development_dependency "bunny", "~> 1.7.0"
32
+ spec.add_development_dependency "simplecov"
32
33
  end
@@ -7,6 +7,7 @@ module Emque
7
7
  attr_accessor :log_publish_message
8
8
  attr_accessor :publish_messages
9
9
  attr_reader :rabbitmq_options
10
+ attr_accessor :ignored_exceptions
10
11
 
11
12
  def initialize
12
13
  @app_name = ""
@@ -17,6 +18,7 @@ module Emque
17
18
  @rabbitmq_options = {
18
19
  :url => "amqp://guest:guest@localhost:5672"
19
20
  }
21
+ @ignored_exceptions = [Emque::Producing::Message::MessagesNotSentError]
20
22
  end
21
23
  end
22
24
  end
@@ -36,6 +36,14 @@ module Emque
36
36
  end
37
37
  end
38
38
 
39
+ def ignored_exceptions(*ignored_exceptions)
40
+ @ignored_exceptions = ignored_exceptions
41
+ end
42
+
43
+ def read_ignored_exceptions
44
+ (Array(@ignored_exceptions) + Emque::Producing.configuration.ignored_exceptions).uniq
45
+ end
46
+
39
47
  def private_attribute(name, coercion=nil, opts={})
40
48
  @private_attrs ||= []
41
49
  @private_attrs << name
@@ -80,6 +88,10 @@ module Emque
80
88
  self.class.read_raise_on_failure
81
89
  end
82
90
 
91
+ def ignored_exceptions
92
+ self.class.read_ignored_exceptions
93
+ end
94
+
83
95
  def valid?
84
96
  invalid_attributes.empty? && topic && message_type
85
97
  end
@@ -97,21 +109,26 @@ module Emque
97
109
  Oj.dump(data, :mode => :compat)
98
110
  end
99
111
 
100
- def publish(publisher=Emque::Producing.publisher)
112
+ def publish(publisher=nil)
113
+ publisher ||= Emque::Producing.publisher
101
114
  log "publishing...", true
102
115
  if valid?
103
116
  log "valid...", true
104
117
  if Emque::Producing.configuration.publish_messages
105
118
  sent = publisher.publish(topic, message_type, to_json, partition_key)
106
119
  log "sent #{sent}"
107
- if raise_on_failure? && !sent
108
- raise MessagesNotSentError.new
109
- end
120
+ raise MessagesNotSentError.new unless sent
110
121
  end
111
122
  else
112
123
  log "failed...", true
113
124
  raise InvalidMessageError.new(invalid_message)
114
125
  end
126
+ rescue *ignored_exceptions => error
127
+ if raise_on_failure?
128
+ raise
129
+ else
130
+ log "failed ignoring exception... #{error}", true
131
+ end
115
132
  end
116
133
 
117
134
  private
@@ -5,6 +5,10 @@ module Emque
5
5
  module Producing
6
6
  module Publisher
7
7
  class RabbitMq < Emque::Producing::Publisher::Base
8
+ Emque::Producing.configure do |c|
9
+ c.ignored_exceptions = c.ignored_exceptions + [Bunny::Exception, Timeout::Error]
10
+ end
11
+
8
12
  CONN = Bunny
9
13
  .new(Emque::Producing.configuration.rabbitmq_options[:url])
10
14
  .tap { |conn|
@@ -1,5 +1,5 @@
1
1
  module Emque
2
2
  module Producing
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -56,6 +56,32 @@ class TestMessageWithChangeset
56
56
  )
57
57
  end
58
58
 
59
+ class TestMessageDontRaiseOnFailure
60
+ include Emque::Producing.message
61
+
62
+ IgnoreThisError = Class.new(StandardError)
63
+ DontIgnoreThisError = Class.new(StandardError)
64
+
65
+ topic "queue"
66
+ message_type "queue.new"
67
+
68
+ ignored_exceptions IgnoreThisError
69
+
70
+ raise_on_failure false
71
+ end
72
+
73
+ class TestPublisher
74
+ InvalidMessageError = Class.new(StandardError)
75
+ TimeoutMessageError = Class.new(StandardError)
76
+
77
+ Emque::Producing.configure do |c|
78
+ c.ignored_exceptions = c.ignored_exceptions + [InvalidMessageError, TimeoutMessageError]
79
+ end
80
+
81
+ def publish(topic, message_type, message, key = nil)
82
+ end
83
+ end
84
+
59
85
  describe Emque::Producing::Message do
60
86
  before { Emque::Producing.configure { |c| c.app_name = "my_app" } }
61
87
 
@@ -260,4 +286,65 @@ describe Emque::Producing::Message do
260
286
  )
261
287
  end
262
288
  end
289
+
290
+ context "raise_on_failure" do
291
+ describe "when false" do
292
+ let(:message) { TestMessageDontRaiseOnFailure.new() }
293
+ let(:publisher) { TestPublisher.new }
294
+
295
+ it "catches exceptions from publisher" do
296
+ allow(Emque::Producing).to receive(:publisher) { raise TestPublisher::InvalidMessageError }
297
+
298
+ expect{message.publish()}.not_to raise_error
299
+ end
300
+
301
+ it "catches exceptions from publish" do
302
+ allow(publisher).to receive(:publish) { raise TestPublisher::TimeoutMessageError }
303
+
304
+ expect{message.publish(publisher)}.not_to raise_error
305
+ end
306
+
307
+ it "catches exceptions when publish doesn't send" do
308
+ allow(publisher).to receive(:publish) { false }
309
+
310
+ expect{message.publish(publisher)}.not_to raise_error
311
+ end
312
+
313
+ it "catches exceptions when publish doesn't send" do
314
+ allow(publisher).to receive(:publish) { raise TestMessageDontRaiseOnFailure::IgnoreThisError }
315
+
316
+ expect{message.publish(publisher)}.not_to raise_error
317
+ end
318
+
319
+ it "doesnt catch an exceptions that isn't in the " do
320
+ allow(publisher).to receive(:publish) { raise TestMessageDontRaiseOnFailure::DontIgnoreThisError }
321
+
322
+ expect{message.publish(publisher)}.to raise_error(TestMessageDontRaiseOnFailure::DontIgnoreThisError)
323
+ end
324
+
325
+ end
326
+
327
+ describe "when true" do
328
+ let(:message) { TestMessage.new(:test_id => 1) }
329
+ let(:publisher) { TestPublisher.new }
330
+
331
+ it "doesn't catch exceptions from publisher" do
332
+ allow(Emque::Producing).to receive(:publisher) { raise TestPublisher::InvalidMessageError }
333
+
334
+ expect{message.publish()}.to raise_error(TestPublisher::InvalidMessageError)
335
+ end
336
+
337
+ it "doesn't catch exceptions from publish" do
338
+ allow(publisher).to receive(:publish) { raise TestPublisher::TimeoutMessageError }
339
+
340
+ expect{message.publish(publisher)}.to raise_error(TestPublisher::TimeoutMessageError)
341
+ end
342
+
343
+ it "doesn't catch exceptions when publish doesn't send" do
344
+ allow(publisher).to receive(:publish) { false }
345
+
346
+ expect{message.publish(publisher)}.to raise_error(Emque::Producing::Message::MessagesNotSentError)
347
+ end
348
+ end
349
+ end
263
350
  end
@@ -1,5 +1,10 @@
1
1
  $TESTING = true
2
2
 
3
+ require "simplecov"
4
+ SimpleCov.start do
5
+ add_filter "spec/"
6
+ end
7
+
3
8
  require "pry"
4
9
  require "emque-producing"
5
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emque-producing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emily Dobervich
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-22 00:00:00.000000000 Z
12
+ date: 2015-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oj
@@ -109,6 +109,20 @@ dependencies:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: 1.7.0
112
+ - !ruby/object:Gem::Dependency
113
+ name: simplecov
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
112
126
  description: Define and send messages to a variety of message brokers
113
127
  email:
114
128
  - emily@teamsnap.com