songkick_queue 0.6.0 → 1.0.0

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: c907eaed6febf237e49b8ff56171ecdd09976fe1
4
- data.tar.gz: ac2c3f1207df01dd24623fef5de6492c1b8016ff
3
+ metadata.gz: 80c905f63588a612193bdeaade449945a882915d
4
+ data.tar.gz: 9efbed0c8e48ab683f5d3a201ce5f185a64b4cd8
5
5
  SHA512:
6
- metadata.gz: 0c1f1c1cd6b38341badd1b4a0065278730ed6caac7193c4d1c35a374076cd0151bad596eb0b00b7abbba312ae67fe5ff6619978b54e176cdee0e372ce8f02702
7
- data.tar.gz: 3d21e628d13199e1467e8bb483432ec6abfe31fbfde4cda5858693450ec1faea565fe1848eb83ddfa2376c4f843739cb8ca0842cba285a9254629b65d01671b5
6
+ metadata.gz: 35eb58b4c453ca4a5516e675d3753bd6a8ee7d9cb4c543f0999b8050b329c681c0e58eb8a4eca8b3de7edd443a11527132e2631fc2ceab6bae1f4ac27dc10dfc
7
+ data.tar.gz: 50c7cc654906e5fa6544ffed3ebb4cb924b885df011a86dabca80cc0faef97ec28fbf8c03dab82abc1be9dc2c968209caff4cffc909ce03049d0c2b30e7f2b0f
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  script: bundle exec rspec
3
3
  rvm:
4
- - 2.2.0
5
- - 2.1.0
6
- - 2.0.0
4
+ - 2.3.1
5
+ - 2.2.2
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0
4
+ ### Added
5
+ - Configuration option: `requeue_rejected_messages`
6
+
7
+ ### Changed
8
+ - Changed default consumer behaviour for errors; we now reject on failure and re-queue according to new config option `requeue_rejected_messages` (defaults to false)
9
+
3
10
  ## 0.6.0
4
11
  ### Added
5
12
  - Instrumentation (for tracking metrics using statsd or other tools)
data/README.md CHANGED
@@ -42,6 +42,7 @@ SongkickQueue.configure do |config|
42
42
  config.vhost = '/'
43
43
  config.max_reconnect_attempts = 10
44
44
  config.network_recovery_interval = 1.0
45
+ config.requeue_rejected_messages = false
45
46
  end
46
47
  ```
47
48
 
@@ -170,8 +171,7 @@ $ open http://localhost:8808/
170
171
 
171
172
  ## TODO
172
173
 
173
- * Add a message UUID when publishing (add to process name when processing)
174
- * Look at adding #requeue and #reject methods in consumer mixin
174
+ * Requeue and reject from within consumers
175
175
 
176
176
  ## Contributing
177
177
 
@@ -22,6 +22,7 @@ module SongkickQueue
22
22
  :vhost,
23
23
  :max_reconnect_attempts,
24
24
  :network_recovery_interval,
25
+ :requeue_rejected_messages,
25
26
  )
26
27
 
27
28
  TooManyReconnectAttemptsError = Class.new(StandardError)
@@ -35,6 +36,7 @@ module SongkickQueue
35
36
  config.port = 5672
36
37
  config.max_reconnect_attempts = 10
37
38
  config.network_recovery_interval = 1.0
39
+ config.requeue_rejected_messages = false
38
40
  end
39
41
  end
40
42
 
@@ -1,3 +1,3 @@
1
1
  module SongkickQueue
2
- VERSION = "0.6.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -103,9 +103,11 @@ module SongkickQueue
103
103
  end
104
104
  rescue Object => exception
105
105
  logger.error(exception)
106
+ channel.reject(delivery_info.delivery_tag, config.requeue_rejected_messages)
107
+ else
108
+ channel.ack(delivery_info.delivery_tag, false)
106
109
  ensure
107
110
  set_process_name
108
- channel.ack(delivery_info.delivery_tag, false)
109
111
  end
110
112
 
111
113
  def channel
@@ -65,24 +65,26 @@ module SongkickQueue
65
65
  end
66
66
 
67
67
  describe "#process_message" do
68
- it "should instantiate the consumer and call #process" do
68
+ let(:worker) { Worker.new(:process_name, BarConsumer) }
69
+ let(:logger) { double(:logger, info: :null) }
70
+ let(:channel) { double(:channel, ack: :null, reject: :null) }
71
+ let(:delivery_info) { double(:delivery_info, delivery_tag: 'tag') }
72
+ let(:consumer) { double(BarConsumer, process: :null) }
73
+ let(:config) { double(:config, requeue_rejected_messages: true) }
74
+
75
+ before do
69
76
  ::BarConsumer = Struct.new(:delivery_info, :logger) do
70
77
  def self.queue_name
71
78
  "bar-queue"
72
79
  end
73
80
  end
74
- worker = Worker.new(:process_name, BarConsumer)
75
81
 
76
- logger = double(:logger, info: :null)
77
82
  allow(worker).to receive(:logger) { logger }
78
-
79
- channel = double(:channel, ack: :null)
80
83
  allow(worker).to receive(:channel) { channel }
84
+ allow(worker).to receive(:config) { config }
85
+ end
81
86
 
82
- delivery_info = double(:delivery_info, delivery_tag: 'tag')
83
-
84
- consumer = double(BarConsumer, process: :null)
85
-
87
+ it "should instantiate the consumer and call #process" do
86
88
  expect(BarConsumer).to receive(:new)
87
89
  .with(delivery_info, logger) { consumer }
88
90
 
@@ -95,9 +97,32 @@ module SongkickQueue
95
97
 
96
98
  expect(logger).to have_received(:info)
97
99
  .with('Processing message 92c583bdc248 via BarConsumer, produced at 2015-03-30T15:41:55Z')
100
+ end
101
+
102
+ it "should acknowedge the message if it is successful" do
103
+ expect(BarConsumer).to receive(:new)
104
+ .with(delivery_info, logger) { consumer }
105
+
106
+ worker.send(:process_message, BarConsumer, delivery_info, :properties,
107
+ '{"message_id":"92c583bdc248","produced_at":"2015-03-30T15:41:55Z",' +
108
+ '"payload":{"example":"message","value":true}}')
98
109
 
99
110
  expect(channel).to have_received(:ack).with('tag', false)
100
111
  end
112
+
113
+ it "should reject and re-queue the message if it is not successful" do
114
+ expect(BarConsumer).to receive(:new)
115
+ .with(delivery_info, logger) { consumer }
116
+
117
+ allow(consumer).to receive(:process) { raise RuntimeError, "test error" }
118
+ expect(logger).to receive(:error).with(instance_of(RuntimeError))
119
+
120
+ worker.send(:process_message, BarConsumer, delivery_info, :properties,
121
+ '{"message_id":"92c583bdc248","produced_at":"2015-03-30T15:41:55Z",' +
122
+ '"payload":{"example":"message","value":true}}')
123
+
124
+ expect(channel).to have_received(:reject).with('tag', true)
125
+ end
101
126
  end
102
127
  end
103
128
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: songkick_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Lucraft
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-27 00:00:00.000000000 Z
12
+ date: 2016-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 2.4.5
153
+ rubygems_version: 2.5.1
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: A gem for processing tasks asynchronously, powered by RabbitMQ.