multiple_man 1.6.1 → 1.6.2

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: 34c76ed50d75d8813d5bfb120ed9b18bdaccaec1
4
- data.tar.gz: 29ce2ff4cd58a046a7f5a4dae146ae73412e4030
3
+ metadata.gz: 7edede56412486d12f76121832ae03ce2a8adcfe
4
+ data.tar.gz: 0eb18f9ac6bb9ef94e54331e0f5d3e4f8f0d39b3
5
5
  SHA512:
6
- metadata.gz: 9f6e04e9f08b36cff2353c38d065a206169536852b409b70091dd2054bf40e1d198da9a8f8aa4525569570562a551164fcde4ad109da23db6e577c83f0ae01ad
7
- data.tar.gz: 9792ce4da51bc92d5e3f65d803d4bce5e0abb1061bf6cf96104a2a3fc119ec7718def7eb853e542299fddc475e5c6eb1c678b6e64b7d4b2dcd687d043b824a18
6
+ metadata.gz: 83796fb767f48cd2d82f19389bfb0423fcf8f478a1faaa1d1bca227b52cdca23e69ef807de931a659f3a3ffd0a142daed4812300238c0a79e7fa80ccc11855f0
7
+ data.tar.gz: 94b64ab2b87b90fad01dde7a3d5a159cc5552f8a995385cb20d37d33357828a105499011bf83f8b5f8749dadf67bb8952d55e1f10395eb8800d1ef300e865417
data/README.md CHANGED
@@ -17,7 +17,9 @@ It's heavily inspired by Promiscuous, but differs in a few ways:
17
17
 
18
18
  Add this line to your application's Gemfile:
19
19
 
20
- gem 'multiple_man'
20
+ ```ruby
21
+ gem 'multiple_man'
22
+ ```
21
23
 
22
24
  And then execute:
23
25
 
@@ -34,39 +36,41 @@ Or install it yourself as:
34
36
  MultipleMan can be configured (ideally inside an initializer) by
35
37
  calling MultipleMan.configure like so:
36
38
 
37
- MultipleMan.configure do |config|
38
- # A connection string to your local server. Defaults to localhost.
39
- config.connection = "amqp://example.com"
39
+ ```ruby
40
+ MultipleMan.configure do |config|
41
+ # A connection string to your local server. Defaults to localhost.
42
+ config.connection = "amqp://example.com"
40
43
 
41
- # The topic name to push to. If you have multiple
42
- # multiple man apps, this should be unique per application. Publishers
43
- # and subscribers should always use the same topic.
44
- config.topic_name = "multiple_man"
44
+ # The topic name to push to. If you have multiple
45
+ # multiple man apps, this should be unique per application. Publishers
46
+ # and subscribers should always use the same topic.
47
+ config.topic_name = "multiple_man"
45
48
 
46
- # The application name (used for subscribers) - defaults to your
47
- # Rails application name if you're using rails
48
- config.app_name = "MyApp"
49
+ # The application name (used for subscribers) - defaults to your
50
+ # Rails application name if you're using rails
51
+ config.app_name = "MyApp"
49
52
 
50
- # Specify what should happen when MultipleMan
51
- # encounters an exception.
52
- config.on_error do |exception|
53
- ErrorLogger.log(exception)
54
- end
53
+ # Specify what should happen when MultipleMan
54
+ # encounters an exception.
55
+ config.on_error do |exception|
56
+ ErrorLogger.log(exception)
57
+ end
55
58
 
56
- # Add opts that go directly to the bunny constructor (Advanced)
57
- config.bunny_opts = {
58
- tls_ca_certificates: ['/usr/lib/ssl/certs/cacert.pem']
59
- }
59
+ # Add opts that go directly to the bunny constructor (Advanced)
60
+ config.bunny_opts = {
61
+ tls_ca_certificates: ['/usr/lib/ssl/certs/cacert.pem']
62
+ }
60
63
 
61
- # Add opts that are used when creating the exchange
62
- config.exchange_opts = {
63
- durable: true
64
- }
64
+ # Add opts that are used when creating the exchange
65
+ config.exchange_opts = {
66
+ durable: true
67
+ }
65
68
 
66
- # Where you want to log errors to. Should be an instance of Logger
67
- # Defaults to the Rails logger (for Rails) or STDOUT otherwise.
68
- config.logger = Logger.new(STDOUT)
69
- end
69
+ # Where you want to log errors to. Should be an instance of Logger
70
+ # Defaults to the Rails logger (for Rails) or STDOUT otherwise.
71
+ config.logger = Logger.new(STDOUT)
72
+ end
73
+ ```
70
74
 
71
75
  ### A note on errors
72
76
 
@@ -85,16 +89,18 @@ cause will be preserved in Exception#cause.
85
89
 
86
90
  Include this in your model definition:
87
91
 
88
- class Widget < ActiveRecord::Base
89
- include MultipleMan::Publisher
90
- publish fields: [:id, :name, :type]
91
- end
92
+ ```ruby
93
+ class Widget < ActiveRecord::Base
94
+ include MultipleMan::Publisher
95
+ publish fields: [:id, :name, :type]
96
+ end
97
+ ```
92
98
 
93
99
  #### In an initializer / config file
94
100
 
95
101
  Add this to an initializer (i.e. `multiple_man.rb`):
96
102
 
97
- ```
103
+ ```ruby
98
104
  MultipleMan.publish Widget, fields: [:id, :name, :type]
99
105
  ```
100
106
 
@@ -120,7 +126,7 @@ You can use the following options when publishing:
120
126
 
121
127
  By default, MultipleMan will publish all of your models whenever you save a model (in an `after_commit` hook). If you need to manually publish models, you can do so with the `multiple_man_publish` method, which acts like a scope on your models, like so:
122
128
 
123
- ```
129
+ ```ruby
124
130
  # Publish all widgets to MultipleMan
125
131
  Widget.multiple_man_publish
126
132
 
@@ -138,10 +144,12 @@ version of multiple_man_publish that operates on a collection. By calling the in
138
144
 
139
145
  You can subscribe to a model as follows (in a seperate consumer app):
140
146
 
141
- class Widget < ActiveRecord::Base
142
- include MultipleMan::Subscriber
143
- subscribe fields: [:id, :name]
144
- end
147
+ ```ruby
148
+ class Widget < ActiveRecord::Base
149
+ include MultipleMan::Subscriber
150
+ subscribe fields: [:id, :name]
151
+ end
152
+ ```
145
153
 
146
154
  You can pass the following options to the `subscribe` call:
147
155
 
@@ -159,7 +167,7 @@ If your publisher specifies an `identifier` option, you *must* include a column
159
167
  If you want to do something other than populate a model on MultipleMan messages,
160
168
  you can listen for messages and process them however you'd like:
161
169
 
162
- ```
170
+ ```ruby
163
171
  def ListenerClass
164
172
  include MultipleMan::Listener
165
173
  listen_to 'ModelName'
@@ -189,7 +197,7 @@ rake multiple_man:seed
189
197
 
190
198
  2. On the publisher side, indicate that your models should be seeded with the following command:
191
199
 
192
- ```
200
+ ```ruby
193
201
  MyModel.multiple_man_publish(:seed)
194
202
  ```
195
203
 
@@ -2,6 +2,7 @@ require 'forwardable'
2
2
 
3
3
  module MultipleMan
4
4
  class Runner
5
+ class ShutDown < Error; end
5
6
  extend Forwardable
6
7
 
7
8
  MODES = [:general, :seed].freeze
@@ -17,6 +18,8 @@ module MultipleMan
17
18
  preload_framework!
18
19
  channel.prefetch(prefetch_size)
19
20
  build_listener.listen
21
+ rescue ShutDown
22
+ connection.close
20
23
  end
21
24
 
22
25
  private
@@ -28,10 +31,8 @@ module MultipleMan
28
31
  def trap_signals!
29
32
  handler = proc do |signal|
30
33
  puts "received #{Signal.signame(signal)}"
31
- channel.close
32
- connection.close
33
34
 
34
- exit
35
+ raise ShutDown
35
36
  end
36
37
 
37
38
  %w(INT QUIT TERM).each { |signal| Signal.trap(signal, handler) }
@@ -1,3 +1,3 @@
1
1
  module MultipleMan
2
- VERSION = "1.6.1"
2
+ VERSION = "1.6.2"
3
3
  end
data/spec/runner_spec.rb CHANGED
@@ -15,26 +15,14 @@ describe MultipleMan::Runner do
15
15
  end
16
16
 
17
17
  context "shutdown" do
18
- let(:mock_consumer) { double("Consumer", listen: ->(_){ sleep(1); raise "no interrupt!" }) }
18
+ let(:connection) { MultipleMan::Connection.connection }
19
19
 
20
- xit 'closes connections and exits gracefully' do
21
- ps = fork do
22
- expect(MultipleMan::Connection).to receive(:connection).and_return(mock_connection)
23
- expect(MultipleMan::Consumers::General).to receive(:new).and_return(mock_consumer)
20
+ it 'closes connections and exits gracefully' do
21
+ MultipleMan::Consumers::General.stub(:new) { Process.kill('INT', 0) }
24
22
 
25
- expect(mock_channel).to receive(:close)
26
- expect(mock_connection).to receive(:close)
23
+ expect(connection).to receive(:close)
27
24
 
28
- described_class.new(mode: :general).run
29
- end
30
-
31
- sleep 0.01
32
-
33
- Process.kill('INT', ps)
34
- a, status = Process.waitpid2(ps)
35
- # binding.pry
36
-
37
- expect(status.success?).to be true
25
+ MultipleMan::Runner.new.run
38
26
  end
39
27
  end
40
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiple_man
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brunner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny