action_subscriber 1.2.3 → 1.3.0.rc0

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: b45c8935406a1754c056083bcd3d1e3c790b59bf
4
- data.tar.gz: 72bf3d2d48e543ebca5f8b991dc354db7f589867
3
+ metadata.gz: 701ee841b7168f2d83ddc0767b410fb4d823fd44
4
+ data.tar.gz: bba2c85bfac1967c60c52435b0142ea40651c78a
5
5
  SHA512:
6
- metadata.gz: 612f9f2a798a366f007ebaaa8125b72df6cf042c5631169b0af72350ecb950b2090c227078e88c94b7809c8ee2c21d7718af5585c2efbc21b7fa8216ce956c1c
7
- data.tar.gz: ec8e589d774df7648aa86b96506038154106c852af43a480c9c60a858bd10726dcb66edc75b4da4565622bbeb96eb2e52f4f42351742bd9f2dfc5236af3246d7
6
+ metadata.gz: 19326dcda78b48629968f5ea1355634824bc8265b4877c9a21d67733beefccbe526f56113aadfb33c1802d6526ba4e132806ffe61599d2180746b9b8cb85c282
7
+ data.tar.gz: 62156cbacea3f77657ca7fa1ed649a1698f450f3c59d7d39866ee82603009b4796751aaede0647cf728091f83f8951093d312a2e1dc7008b9a03abf5b03a845d
@@ -11,6 +11,7 @@ module ActionSubscriber
11
11
  class_option :mode
12
12
  class_option :host
13
13
  class_option :hosts
14
+ class_option :prefetch, :type => :numeric, :desc => "how many messages to hold in the local queue in subscribe mode"
14
15
  class_option :pop_interval, :type => :numeric, :desc => "how long to wait between asking for messages (in milliseconds)"
15
16
  class_option :port, :type => :numeric
16
17
  class_option :threadpool_size, :type => :numeric
@@ -39,23 +40,16 @@ module ActionSubscriber
39
40
  end
40
41
  end
41
42
 
42
- [:INT, :QUIT, :TERM].each do |signal|
43
- trap(signal) do
44
- puts "Stopping server..."
45
- wait_loops = 0
43
+ if ::RUBY_PLATFORM == "java"
44
+ at_exit do
46
45
  ::ActionSubscriber::Babou.stop_server!
47
-
48
- # Going to wait until the thread pool drains or we wait for 1000 seconds
49
- # Only waiting for shut down in pop mode
50
- if ::ActionSubscriber::Babou.pop?
51
- while ::ActionSubscriber::Threadpool.pool.busy_size > 0 && wait_loops < 1000
52
- Thread.pass
53
- wait_loops = wait_loops + 1
54
- sleep 1
55
- end
46
+ end
47
+ else
48
+ [:INT, :QUIT, :TERM].each do |signal|
49
+ trap(signal) do
50
+ ::ActionSubscriber::Babou.stop_server!
51
+ exit 0
56
52
  end
57
-
58
- exit 0
59
53
  end
60
54
  end
61
55
  end
@@ -18,7 +18,7 @@ module ActionSubscriber
18
18
  # default check interval to 100ms
19
19
  while true
20
20
  ::ActionSubscriber.auto_pop! unless shutting_down?
21
- sleep sleep_time
21
+ sleep sleep_time
22
22
  break if shutting_down?
23
23
  end
24
24
  end
@@ -74,12 +74,34 @@ module ActionSubscriber
74
74
  end
75
75
  end
76
76
 
77
- def self.stop_server!
77
+ def self.shutting_down?
78
+ !!@shutting_down
79
+ end
80
+
81
+ def self.stop_receving_messages!
78
82
  @shutting_down = true
83
+ ::Thread.new do
84
+ ::ActionSubscriber::Base.inherited_classes.each do |subscriber|
85
+ subscriber.cancel_consumers!
86
+ puts "finished cancelling consumers"
87
+ end
88
+ end.join
79
89
  end
80
90
 
81
- def self.shutting_down?
82
- !!@shutting_down
91
+ def self.stop_server!
92
+ puts "Stopping server..."
93
+ wait_loops = 0
94
+ ::ActionSubscriber::Babou.stop_receving_messages!
95
+
96
+ # Going to wait until the thread pool drains or we wait for 1000 seconds
97
+ while ::ActionSubscriber::Threadpool.pool.busy_size > 0 && wait_loops < 1000
98
+ puts "waiting for threadpool to empty (#{::ActionSubscriber::Threadpool.pool.busy_size})"
99
+ Thread.pass
100
+ wait_loops = wait_loops + 1
101
+ sleep 1
102
+ end
103
+
104
+ puts "threadpool empty. Shutting down"
83
105
  end
84
106
 
85
107
  def self.subscribers_loaded?
@@ -1,6 +1,15 @@
1
1
  module ActionSubscriber
2
2
  module Bunny
3
3
  module Subscriber
4
+ def bunny_consumers
5
+ @bunny_consumers ||= []
6
+ end
7
+
8
+ def cancel_consumers!
9
+ puts "cancelling consumers for #{self}"
10
+ bunny_consumers.each(&:cancel)
11
+ end
12
+
4
13
  def auto_pop!
5
14
  # Because threadpools can be large we want to cap the number
6
15
  # of times we will pop each time we poll the broker
@@ -26,8 +35,10 @@ module ActionSubscriber
26
35
 
27
36
  def auto_subscribe!
28
37
  queues.each do |queue|
29
- queue.channel.prefetch(::ActionSubscriber.config.prefetch) if acknowledge_messages?
30
- queue.subscribe(queue_subscription_options) do |delivery_info, properties, encoded_payload|
38
+ channel = queue.channel
39
+ channel.prefetch(::ActionSubscriber.config.prefetch) if acknowledge_messages?
40
+ consumer = ::Bunny::Consumer.new(channel, queue, channel.generate_consumer_tag, !acknowledge_messages?)
41
+ consumer.on_delivery do |delivery_info, properties, encoded_payload|
31
42
  ::ActiveSupport::Notifications.instrument "received_event.action_subscriber", :payload_size => encoded_payload.bytesize, :queue => queue.name
32
43
  properties = {
33
44
  :channel => queue.channel,
@@ -40,6 +51,8 @@ module ActionSubscriber
40
51
  env = ::ActionSubscriber::Middleware::Env.new(self, encoded_payload, properties)
41
52
  enqueue_env(env)
42
53
  end
54
+ bunny_consumers << consumer
55
+ queue.subscribe_with(consumer)
43
56
  end
44
57
  end
45
58
 
@@ -1,6 +1,11 @@
1
1
  module ActionSubscriber
2
2
  module MarchHare
3
3
  module Subscriber
4
+ def cancel_consumers!
5
+ puts "cancelling consumers for #{self}"
6
+ march_hare_consumers.each(&:cancel)
7
+ end
8
+
4
9
  def auto_pop!
5
10
  # Because threadpools can be large we want to cap the number
6
11
  # of times we will pop each time we poll the broker
@@ -30,7 +35,7 @@ module ActionSubscriber
30
35
  def auto_subscribe!
31
36
  queues.each do |queue|
32
37
  queue.channel.prefetch = ::ActionSubscriber.config.prefetch if acknowledge_messages?
33
- queue.subscribe(queue_subscription_options) do |header, encoded_payload|
38
+ consumer = queue.subscribe(queue_subscription_options) do |header, encoded_payload|
34
39
  ::ActiveSupport::Notifications.instrument "received_event.action_subscriber", :payload_size => encoded_payload.bytesize, :queue => queue.name
35
40
  properties = {
36
41
  :channel => queue.channel,
@@ -43,9 +48,15 @@ module ActionSubscriber
43
48
  env = ::ActionSubscriber::Middleware::Env.new(self, encoded_payload, properties)
44
49
  enqueue_env(env)
45
50
  end
51
+
52
+ march_hare_consumers << consumer
46
53
  end
47
54
  end
48
55
 
56
+ def march_hare_consumers
57
+ @march_hare_consumers ||= []
58
+ end
59
+
49
60
  private
50
61
 
51
62
  def enqueue_env(env)
@@ -25,12 +25,10 @@ module ActionSubscriber
25
25
  end
26
26
  end
27
27
 
28
- def self.publishing_options(route, in_options = {})
29
- options = {
30
- :mandatory => false,
31
- :persistent => false,
32
- :routing_key => route,
33
- }.merge(in_options)
28
+ def self.publishing_options(route, options = {})
29
+ options[:mandatory] = false unless options.key(:mandatory)
30
+ options[:persistent] = false unless options.key(:persistent)
31
+ options[:routing_key] = route
34
32
 
35
33
  if ::RUBY_PLATFORM == "java"
36
34
  java_options = {}
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "1.2.3"
2
+ VERSION = "1.3.0.rc0"
3
3
  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: 1.2.3
4
+ version: 1.3.0.rc0
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: 2015-10-13 00:00:00.000000000 Z
15
+ date: 2015-10-14 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -255,9 +255,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
255
255
  version: '0'
256
256
  required_rubygems_version: !ruby/object:Gem::Requirement
257
257
  requirements:
258
- - - ">="
258
+ - - ">"
259
259
  - !ruby/object:Gem::Version
260
- version: '0'
260
+ version: 1.3.1
261
261
  requirements: []
262
262
  rubyforge_project:
263
263
  rubygems_version: 2.4.8