propono 1.2.0 → 1.3.0

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: 19a7aae1334abb194ea3fe2ca03a3b7d6641a9b0
4
- data.tar.gz: 181145ff80cc31864884a2ed6f6ca3b2c8757f24
3
+ metadata.gz: 8cbff5dcb118c99e3f7ff39f3cfc172e478edb5e
4
+ data.tar.gz: 619b6da2339dd1a0c9feea52b4851e0735f6a826
5
5
  SHA512:
6
- metadata.gz: 43c3d394220ac21226e33245ea52e10e07cb093a367c4747c750421c6c99f8e7267692f8470f1e5b885f7eef60571f9d0e6af1f355ea8e62773f3d8583684df3
7
- data.tar.gz: f69c5512d119490b0ef13bd2fd8b219166f660f724cd6539a1176e987ea8d821b8310277700868ed6dff2e42429f252c802eea166535cb8a9af9ecf582248cbd
6
+ metadata.gz: bf7e492a492a3a31dd40fede408e1b084f996aff7b057f1747617a10f8d217028d2dca4541d381dd0da70612e89ca2b91b4d3a91696036e057a3504940760b47
7
+ data.tar.gz: f9fec93fc0c85902123a9b6d5c608ef711a89853e01502fd70d3c563797889707b14687522bd302abe5eeb039951d1a43a1bf94add6286955c6675533796dacb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 1.3.0 / 2014-07-12
2
+ * [FEATURE] Add {async: false} option to publisher
3
+
1
4
  # 1.2.0 / 2014-05-25
2
5
  * [BUGFIX] Restrict SQS policy to only allow SNS topic publishes.
3
6
 
@@ -11,7 +11,7 @@ module Propono
11
11
  new(topic_id, message, options).publish
12
12
  end
13
13
 
14
- attr_reader :topic_id, :message, :protocol, :id
14
+ attr_reader :topic_id, :message, :protocol, :id, :async
15
15
 
16
16
  def initialize(topic_id, message, options = {})
17
17
  raise PublisherError.new("Topic is nil") if topic_id.nil?
@@ -24,6 +24,7 @@ module Propono
24
24
  @protocol = options.fetch(:protocol, :sns).to_sym
25
25
  @id = SecureRandom.hex(3)
26
26
  @id = "#{options[:id]}-#{@id}" if options[:id]
27
+ @async = options.fetch(:async, true)
27
28
  end
28
29
 
29
30
  def publish
@@ -34,20 +35,26 @@ module Propono
34
35
  private
35
36
 
36
37
  def publish_via_sns
37
- Thread.new do
38
- begin
39
- topic = TopicCreator.find_or_create(topic_id)
40
- rescue => e
41
- Propono.config.logger.error "Propono [#{id}]: Failed to create topic #{topic_id}: #{e}"
42
- raise
43
- end
44
-
45
- begin
46
- sns.publish(topic.arn, body.to_json)
47
- rescue => e
48
- Propono.config.logger.error "Propono [#{id}]: Failed to send via sns: #{e}"
49
- raise
50
- end
38
+ async ? publish_via_sns_asyncronously : publish_via_sns_syncronously
39
+ end
40
+
41
+ def publish_via_sns_asyncronously
42
+ Thread.new { publish_via_sns_syncronously }
43
+ end
44
+
45
+ def publish_via_sns_syncronously
46
+ begin
47
+ topic = TopicCreator.find_or_create(topic_id)
48
+ rescue => e
49
+ Propono.config.logger.error "Propono [#{id}]: Failed to create topic #{topic_id}: #{e}"
50
+ raise
51
+ end
52
+
53
+ begin
54
+ sns.publish(topic.arn, body.to_json)
55
+ rescue => e
56
+ Propono.config.logger.error "Propono [#{id}]: Failed to send via sns: #{e}"
57
+ raise
51
58
  end
52
59
  end
53
60
 
@@ -1,3 +1,3 @@
1
1
  module Propono
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -36,8 +36,8 @@ module Propono
36
36
 
37
37
  sleep(1) # Make sure the listener has started
38
38
 
39
- Propono.publish(slow_topic, slow_text)
40
- Propono.publish(topic, text)
39
+ Propono.publish(slow_topic, slow_text, async: false)
40
+ Propono.publish(topic, text, async: false)
41
41
  flunks << "Test Timeout" unless wait_for_thread(thread)
42
42
  flunk(flunks.join("\n")) unless flunks.empty?
43
43
  ensure
@@ -35,7 +35,7 @@ module Propono
35
35
 
36
36
  tcp_thread = Thread.new do
37
37
  Propono.listen_to_tcp do |tcp_topic, tcp_message|
38
- Propono.publish(tcp_topic, tcp_message)
38
+ Propono.publish(tcp_topic, tcp_message, async: false)
39
39
  tcp_thread.terminate
40
40
  end
41
41
  end
@@ -223,5 +223,17 @@ module Propono
223
223
  end
224
224
  end
225
225
 
226
+ def test_publish_can_be_called_syncronously
227
+ publisher = Publisher.new("topic_id", "message", async: false)
228
+ publisher.expects(:publish_via_sns_syncronously).once
229
+ publisher.expects(:publish_via_sns_asyncronously).never
230
+ publisher.send(:publish_via_sns)
231
+ end
232
+
233
+ def test_publish_is_normally_called_asyncronously
234
+ publisher = Publisher.new("topic_id", "message")
235
+ publisher.expects(:publish_via_sns_asyncronously)
236
+ publisher.send(:publish_via_sns)
237
+ end
226
238
  end
227
239
  end
@@ -25,7 +25,7 @@ module Propono
25
25
 
26
26
  @listener = QueueListener.new(@topic_id) {}
27
27
  @listener.stubs(sqs: @sqs)
28
-
28
+
29
29
  Propono.config.max_retries = 0
30
30
  end
31
31
 
@@ -157,7 +157,7 @@ module Propono
157
157
  @listener.stubs(:requeue_message_on_failure).with(SqsMessage.new(@sqs_message2), exception)
158
158
  @listener.send(:read_messages_from_queue, queue_url, 10)
159
159
  end
160
-
160
+
161
161
  def test_messages_are_retried_or_abandoned_on_failure
162
162
  queue_url = "test-queue-url"
163
163
 
@@ -198,7 +198,7 @@ module Propono
198
198
  @sqs.expects(:send_message).with(regexp_matches(/https:\/\/queue.amazonaws.com\/[0-9]+\/MyApp-some-topic-failed/), anything)
199
199
  @listener.send(:requeue_message_on_failure, SqsMessage.new(@sqs_message1), StandardError.new)
200
200
  end
201
-
201
+
202
202
  def test_message_requeued_if_there_is_an_exception_but_failure_count_less_than_retry_count
203
203
  Propono.config.max_retries = 5
204
204
  message = SqsMessage.new(@sqs_message1)
@@ -206,7 +206,7 @@ module Propono
206
206
  @sqs.expects(:send_message).with(regexp_matches(/https:\/\/queue.amazonaws.com\/[0-9]+\/MyApp-some-topic$/), anything)
207
207
  @listener.send(:requeue_message_on_failure, message, StandardError.new)
208
208
  end
209
-
209
+
210
210
  def test_message_requeued_if_there_is_an_exception_but_failure_count_exceeds_than_retry_count
211
211
  Propono.config.max_retries = 5
212
212
  message = SqsMessage.new(@sqs_message1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propono
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MalcyL
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-28 00:00:00.000000000 Z
12
+ date: 2014-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  version: '0'
180
180
  requirements: []
181
181
  rubyforge_project:
182
- rubygems_version: 2.2.1
182
+ rubygems_version: 2.1.9
183
183
  signing_key:
184
184
  specification_version: 4
185
185
  summary: General purpose pub/sub library built on top of AWS SNS and SQS