action_subscriber 4.2.2 → 4.2.3.pre

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: 594de0a5e663d38d4e62b13f79397aaa0cfe3ac9
4
- data.tar.gz: 6197131691887782ba9954c4b14e28d32e34bfca
3
+ metadata.gz: 45ae69689291e9fcda93dc4b92648b224add38d0
4
+ data.tar.gz: 01b00b6b55bd1a4c4995021c6e4843b0707ee756
5
5
  SHA512:
6
- metadata.gz: f562a6485494250754c8accab507d1a7734461b889bfefd6fda4f51fe02cbdfe58bc26b344a11eaf86804e10cbdfdcbc3ed474755d2b7ad2d7cbe210ebada5b8
7
- data.tar.gz: 00921c4ac4c2c366e05b975486609fec0645fb0e60b6fa974154d7c3b6782d00dac4277256e3c3d183e09088ae220b547e0eda73bcd024ab167d86973792d793
6
+ metadata.gz: 41e3a0fbac6c65b5c7b04abe3f44dcd18132ab2d8cbe24583958c22805a9b285efaf4cc3a60c90d1de2c86559e06a2e33340562a539165f065719a9251f2069f
7
+ data.tar.gz: 34bba997f2819957baa13da7ac0edf956dd66fc0477ad388fcb43fe99762eeb96d0dd41e8afd08a92058e56c45d3c11e4e9cc92a08841c1481b04218425e3aca
data/README.md CHANGED
@@ -88,6 +88,29 @@ $ bundle exec action_subscriber start
88
88
 
89
89
  This will connect your subscribers to the rabbitmq broker and allow it to push messages down to your subscribers.
90
90
 
91
+ ### Around Filters
92
+ "around" filters are responsible for running their associated actions by yielding, similar to how Rack middlewares work (and Rails around filters work)
93
+
94
+ ```ruby
95
+ class UserSubscriber < ::ActionSubscriber::Base
96
+ around_filter :log_things
97
+
98
+ def created
99
+ # do something when a user is created
100
+ end
101
+
102
+ private
103
+
104
+ def log_things
105
+ puts "before I do some stuff"
106
+ yield
107
+ puts "I did some stuff"
108
+ end
109
+ end
110
+ ```
111
+
112
+ > Warning: an around filter will only be added once to the chain, duplicate around filters are not supported
113
+
91
114
  Configuration
92
115
  -----------------
93
116
  ActionSubscriber needs to know how to connect to your rabbit server to start getting messages.
@@ -140,6 +163,30 @@ Rabbit is told to expect message acknowledgements, but sending the acknowledgeme
140
163
  We send the acknowledgement right after calling your subscriber.
141
164
  If an error is raised your message will be retried on a sent back to rabbitmq and retried on an exponential backoff schedule.
142
165
 
166
+ ### retry
167
+
168
+ A message can be sent to "retry" with `::ActionSubscriber::MessageRetry.redeliver_message_with_backoff` or the DSL method `retry` and optionally
169
+ takes a "backoff schedule" which is a hash of backoff milliseconds for each retry, the default:
170
+
171
+ ```ruby
172
+ SCHEDULE = {
173
+ 2 => 100,
174
+ 3 => 500,
175
+ 4 => 2_500,
176
+ 5 => 12_500,
177
+ 6 => 62_500,
178
+ 7 => 312_500,
179
+ 8 => 1_562_500,
180
+ 9 => 7_812_500,
181
+ 10 => 39_062_500,
182
+ }
183
+ ```
184
+
185
+ when the schedule "returns" `nil` the message will not be retried
186
+
187
+ > Warning: If you use `retry` you need to handle reject/acknowledge according how errors are handled; if an error is caught and the
188
+ > ack/reject is already done then you may duplicate the message in `at_least_once!` mode
189
+
143
190
  Testing
144
191
  -----------------
145
192
  ActionSubscriber includes support for easy unit testing with RSpec.
@@ -59,5 +59,9 @@ module ActionSubscriber
59
59
  def reject
60
60
  env.reject
61
61
  end
62
+
63
+ def retry(backoff_schedule = ::ActionSubscriber::MessageRetry::SCHEDULE)
64
+ ::ActionSubscriber::MessageRetry::redeliver_message_with_backoff(env, backoff_schedule)
65
+ end
62
66
  end
63
67
  end
@@ -23,6 +23,9 @@ module ActionSubscriber
23
23
  logger.info " -- routing_key: #{route.routing_key}"
24
24
  logger.info " -- prefetch: #{route.prefetch}"
25
25
  logger.error "WARNING having a prefetch lower than your concurrency will prevent your subscriber from fully utilizing its threadpool" if route.prefetch < route.concurrency
26
+ if route.acknowledgements != subscriber.acknowledge_messages?
27
+ logger.error "WARNING subscriber has acknowledgements as #{subscriber.acknowledge_messages?} and route has acknowledgements as #{route.acknowledgements}"
28
+ end
26
29
  end
27
30
  end
28
31
  end
@@ -23,7 +23,8 @@ module ActionSubscriber
23
23
  end
24
24
 
25
25
  def around_filter(filter_method)
26
- around_filters << filter_method
26
+ around_filters << filter_method unless around_filters.include?(filter_method)
27
+ around_filters
27
28
  end
28
29
 
29
30
  def around_filters
@@ -23,6 +23,9 @@ module ActionSubscriber
23
23
  logger.info " -- queue: #{route.queue}"
24
24
  logger.info " -- routing_key: #{route.routing_key}"
25
25
  logger.info " -- prefetch: #{route.prefetch} per consumer (#{route.prefetch * route.concurrency} total)"
26
+ if route.acknowledgements != subscriber.acknowledge_messages?
27
+ logger.error "WARNING subscriber has acknowledgements as #{subscriber.acknowledge_messages?} and route has acknowledgements as #{route.acknowledgements}"
28
+ end
26
29
  end
27
30
  end
28
31
  end
@@ -12,9 +12,9 @@ module ActionSubscriber
12
12
  10 => 39_062_500,
13
13
  }.freeze
14
14
 
15
- def self.redeliver_message_with_backoff(env)
15
+ def self.redeliver_message_with_backoff(env, backoff_schedule = SCHEDULE)
16
16
  next_attempt = get_last_attempt_number(env) + 1
17
- ttl = SCHEDULE[next_attempt]
17
+ ttl = backoff_schedule[next_attempt]
18
18
  return unless ttl
19
19
  retry_queue_name = "#{env.queue}.retry_#{ttl}"
20
20
  with_exchange(env, ttl, retry_queue_name) do |exchange|
@@ -47,6 +47,20 @@ module ActionSubscriber
47
47
  end
48
48
  end
49
49
 
50
+ def local_application_name
51
+ @_local_application_name ||= begin
52
+ local_application_name = case
53
+ when ENV['APP_NAME'] then
54
+ ENV['APP_NAME'].to_s.dup
55
+ when defined?(::Rails) then
56
+ ::Rails.application.class.parent_name.dup
57
+ else
58
+ raise "Define an application name (ENV['APP_NAME'])"
59
+ end
60
+ local_application_name.downcase
61
+ end
62
+ end
63
+
50
64
  def resource_name(route_settings)
51
65
  route_settings[:subscriber].name.underscore.gsub(/_subscriber/, "").to_s
52
66
  end
@@ -61,19 +75,5 @@ module ActionSubscriber
61
75
  def routes
62
76
  @routes ||= []
63
77
  end
64
-
65
- def local_application_name
66
- @_local_application_name ||= begin
67
- local_application_name = case
68
- when ENV['APP_NAME'] then
69
- ENV['APP_NAME'].to_s.dup
70
- when defined?(::Rails) then
71
- ::Rails.application.class.parent_name.dup
72
- else
73
- raise "Define an application name (ENV['APP_NAME'])"
74
- end
75
- local_application_name.downcase
76
- end
77
- end
78
78
  end
79
79
  end
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "4.2.2"
2
+ VERSION = "4.2.3.pre"
3
3
  end
@@ -1,6 +1,9 @@
1
1
  class InstaSubscriber < ActionSubscriber::Base
2
2
  around_filter :whisper
3
3
  around_filter :yell
4
+ around_filter :whisper
5
+ around_filter :whisper
6
+ around_filter :yell
4
7
 
5
8
  def first
6
9
  $messages << payload
@@ -29,6 +32,10 @@ describe "subscriber filters", :integration => true do
29
32
  end
30
33
  let(:subscriber) { InstaSubscriber }
31
34
 
35
+ it "does not allow an around filter to be pushed on twice" do
36
+ expect(InstaSubscriber.around_filters).to eq([:whisper, :yell])
37
+ end
38
+
32
39
  it "runs multiple around filters" do
33
40
  $messages = [] #testing the order of things
34
41
  ::ActionSubscriber.start_subscribers!
@@ -11,7 +11,8 @@ describe ActionSubscriber::Middleware::ActiveRecord::QueryCache do
11
11
  allow(connection).to receive(:enable_query_cache!)
12
12
 
13
13
  allow(ActiveRecord::Base).to receive(:connection).and_return(connection)
14
- allow(ActiveRecord::Base).to receive(:connection_id)
14
+ # Rails 5 "compat"
15
+ allow(ActiveRecord::Base).to receive(:connection_id) if ::ActiveRecord::Base.respond_to?(:connection_id)
15
16
  end
16
17
 
17
18
  subject { described_class.new(app) }
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: 4.2.2
4
+ version: 4.2.3.pre
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: 2017-04-20 00:00:00.000000000 Z
15
+ date: 2017-07-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -277,9 +277,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
277
277
  version: '0'
278
278
  required_rubygems_version: !ruby/object:Gem::Requirement
279
279
  requirements:
280
- - - ">="
280
+ - - ">"
281
281
  - !ruby/object:Gem::Version
282
- version: '0'
282
+ version: 1.3.1
283
283
  requirements: []
284
284
  rubyforge_project:
285
285
  rubygems_version: 2.6.10