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 +4 -4
- data/README.md +48 -40
- data/lib/multiple_man/runner.rb +4 -3
- data/lib/multiple_man/version.rb +1 -1
- data/spec/runner_spec.rb +5 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7edede56412486d12f76121832ae03ce2a8adcfe
|
4
|
+
data.tar.gz: 0eb18f9ac6bb9ef94e54331e0f5d3e4f8f0d39b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
64
|
+
# Add opts that are used when creating the exchange
|
65
|
+
config.exchange_opts = {
|
66
|
+
durable: true
|
67
|
+
}
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
|
data/lib/multiple_man/runner.rb
CHANGED
@@ -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
|
-
|
35
|
+
raise ShutDown
|
35
36
|
end
|
36
37
|
|
37
38
|
%w(INT QUIT TERM).each { |signal| Signal.trap(signal, handler) }
|
data/lib/multiple_man/version.rb
CHANGED
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(:
|
18
|
+
let(:connection) { MultipleMan::Connection.connection }
|
19
19
|
|
20
|
-
|
21
|
-
|
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
|
-
|
26
|
-
expect(mock_connection).to receive(:close)
|
23
|
+
expect(connection).to receive(:close)
|
27
24
|
|
28
|
-
|
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.
|
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-
|
11
|
+
date: 2017-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|