action_subscriber 5.1.3 → 5.1.4.pre0

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
  SHA256:
3
- metadata.gz: f884d601b60838334dce94ba6e08e904df922b0f991f5ecd1a0bfe953c41558b
4
- data.tar.gz: b752581b847754666baed507650f90d150ed05f19a7b7166f3ceca9eef0ad92e
3
+ metadata.gz: be413ce9308a022df33f96d787b50b059bd6700911e1a090f98f454777d14a1f
4
+ data.tar.gz: c09a951d4f0343dc9cb2e23484333656fae3111b5e558668436d3fbdf63d0379
5
5
  SHA512:
6
- metadata.gz: '055496ce9efc31b2f86e22e24672859e783a5810d2b36fd55430ac50a1ad3888b09bed824a69678744e579b5542f971d00e3a127f5fb1ffdb22a61f4d3f08683'
7
- data.tar.gz: 4a2f7d618dcb62687904ae5d170b4b7efc9f63eedf6d5ee8c81e50e1e2da7aef17a5b691610b51a320be683c67fe46e10fb6ce58be9b25b5bcc0c557187d4bfa
6
+ metadata.gz: c303e23007ddc09b9bb05d09f269d637ce0e7ac8b7ec0c7325412d9afd84fb81f94590e3230716101c82be2799ae9223745ea8e79595e3bd669e932127588351
7
+ data.tar.gz: 4920a7deec1c46b47c9de7bd467b16ef8e5995050da4c1244c113115bde344fd1b27781e925d72fa1dfa391f2a6adf40ca22c7cd608f5e47ba8cac834c8caa8f
@@ -3,6 +3,10 @@ require "securerandom"
3
3
  module ActionSubscriber
4
4
  module Middleware
5
5
  class Env
6
+ ACK_INSTRUMENT_KEY = "message_acked.action_subscriber".freeze
7
+ NACK_INSTRUMENT_KEY = "message_nacked.action_subscriber".freeze
8
+ REJECT_INSTRUMENT_KEY = "message_rejected.action_subscriber".freeze
9
+
6
10
  attr_accessor :payload
7
11
 
8
12
  attr_reader :action,
@@ -50,7 +54,9 @@ module ActionSubscriber
50
54
  return true if @has_been_acked
51
55
  acknowledge_multiple_messages = false
52
56
  @has_been_acked = true
53
- @channel.ack(@delivery_tag, acknowledge_multiple_messages)
57
+ instrument_for(ACK_INSTRUMENT_KEY) do
58
+ @channel.ack(@delivery_tag, acknowledge_multiple_messages)
59
+ end
54
60
  true
55
61
  end
56
62
 
@@ -65,7 +71,9 @@ module ActionSubscriber
65
71
  nack_multiple_messages = false
66
72
  requeue_message = true
67
73
  @has_been_nacked = true
68
- @channel.nack(@delivery_tag, nack_multiple_messages, requeue_message)
74
+ instrument_for(NACK_INSTRUMENT_KEY) do
75
+ @channel.nack(@delivery_tag, nack_multiple_messages, requeue_message)
76
+ end
69
77
  true
70
78
  end
71
79
 
@@ -74,7 +82,9 @@ module ActionSubscriber
74
82
  return true if @has_been_rejected
75
83
  requeue_message = true
76
84
  @has_been_rejected = true
77
- @channel.reject(@delivery_tag, requeue_message)
85
+ instrument_for(REJECT_INSTRUMENT_KEY) do
86
+ @channel.reject(@delivery_tag, requeue_message)
87
+ end
78
88
  true
79
89
  end
80
90
 
@@ -107,6 +117,12 @@ module ActionSubscriber
107
117
  @has_been_acked || @has_been_nacked || @has_been_rejected
108
118
  end
109
119
 
120
+ def instrument_for(instrumentation_key)
121
+ ::ActiveSupport::Notifications.instrument(instrumentation_key, :subscriber => subscriber.to_s, :routing_key => routing_key, :queue => queue) do
122
+ yield
123
+ end
124
+ end
125
+
110
126
  def uses_acknowledgements?
111
127
  @uses_acknowledgements
112
128
  end
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "5.1.3"
2
+ VERSION = "5.1.4.pre0"
3
3
  end
@@ -30,6 +30,33 @@ describe ActionSubscriber::Middleware::Env do
30
30
  expect(channel).to receive(:ack).with(properties[:delivery_tag], false)
31
31
  subject.acknowledge
32
32
  end
33
+
34
+ it "instruments an acknowedgement" do
35
+ expect(channel).to receive(:ack).with(properties[:delivery_tag], false)
36
+ duration = nil
37
+ work = lambda { |_name, start, finish, _id, _payload| duration = finish - start }
38
+ with_instrumentation_subscription("message_acked.action_subscriber", work) do
39
+ subject.acknowledge
40
+ end
41
+ expect(duration).to_not be_nil
42
+ end
43
+ end
44
+
45
+ describe "#nack" do
46
+ it "sends a nack to rabbitmq" do
47
+ expect(channel).to receive(:nack).with(properties[:delivery_tag], false, true)
48
+ subject.nack
49
+ end
50
+
51
+ it "instruments a nack" do
52
+ expect(channel).to receive(:nack).with(properties[:delivery_tag], false, true)
53
+ duration = nil
54
+ work = lambda { |_name, start, finish, _id, _payload| duration = finish - start }
55
+ with_instrumentation_subscription("message_nacked.action_subscriber", work) do |c|
56
+ subject.nack
57
+ end
58
+ expect(duration).to_not be_nil
59
+ end
33
60
  end
34
61
 
35
62
  describe "#reject" do
@@ -37,6 +64,16 @@ describe ActionSubscriber::Middleware::Env do
37
64
  expect(channel).to receive(:reject).with(properties[:delivery_tag], true)
38
65
  subject.reject
39
66
  end
67
+
68
+ it "instruments a rejection" do
69
+ expect(channel).to receive(:reject).with(properties[:delivery_tag], true)
70
+ duration = nil
71
+ work = lambda { |_name, start, finish, _id, _payload| duration = finish - start }
72
+ with_instrumentation_subscription("message_rejected.action_subscriber", work) do
73
+ subject.reject
74
+ end
75
+ expect(duration).to_not be_nil
76
+ end
40
77
  end
41
78
 
42
79
  describe "#to_hash" do
@@ -51,3 +51,15 @@ def verify_expectation_within(number_of_seconds, check_every = 0.02)
51
51
  end
52
52
  end
53
53
  end
54
+
55
+ # This helper method allows us to verify a subscription is cleaned up after every test.
56
+ # Its arguments are the instrumentation key and a proc that contains the work to be
57
+ # performed for each notification.
58
+ def with_instrumentation_subscription(instrumentation_key, work)
59
+ subscription = ::ActiveSupport::Notifications.subscribe(instrumentation_key) do |name, start, finish, id, payload|
60
+ work.call(name, start, finish, id, payload)
61
+ end
62
+ yield
63
+ ensure
64
+ ::ActiveSupport::Notifications.unsubscribe(subscription)
65
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_subscriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.3
4
+ version: 5.1.4.pre0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Stien
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-11-12 00:00:00.000000000 Z
15
+ date: 2018-11-30 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -292,12 +292,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
292
292
  version: '0'
293
293
  required_rubygems_version: !ruby/object:Gem::Requirement
294
294
  requirements:
295
- - - ">="
295
+ - - ">"
296
296
  - !ruby/object:Gem::Version
297
- version: '0'
297
+ version: 1.3.1
298
298
  requirements: []
299
299
  rubyforge_project:
300
- rubygems_version: 2.7.7
300
+ rubygems_version: 2.7.6
301
301
  signing_key:
302
302
  specification_version: 4
303
303
  summary: ActionSubscriber is a DSL that allows a rails app to consume messages from