multiple_man 1.0.0 → 1.1.0
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/bin/multiple_man +11 -0
- data/lib/multiple_man.rb +3 -1
- data/lib/multiple_man/cli.rb +39 -0
- data/lib/multiple_man/runner.rb +83 -0
- data/lib/multiple_man/tasks/worker.rake +4 -32
- data/lib/multiple_man/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 620155bba7ed083d04162d64106eabcaca533bbd
|
4
|
+
data.tar.gz: 313cb2f92c8a02e48fea9b4f4208531c42f97753
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2afc286f24e1e82ce7809984c67358d71852deab99093d48d5a6aa383877741b754246fa2ea843ceefb04a5f79563a9ce152eaa8cd42e5376ddc90b402e24d22
|
7
|
+
data.tar.gz: ed09d9f96992efaeae2cfb4f55f260b35b89623eb5a17c51bef351ad29672c632d1ac170060d76ff2f980e7af85c09474e6ded21593aacff982ca915701d8dd4
|
data/bin/multiple_man
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Add gem directory to load path - (compatible with Ruby 1.9+)
|
4
|
+
$LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__))
|
5
|
+
|
6
|
+
# Add the current working directory to the load path so we can load the config/environment
|
7
|
+
$LOAD_PATH.unshift Dir.pwd
|
8
|
+
|
9
|
+
require 'multiple_man'
|
10
|
+
|
11
|
+
MultipleMan::CLI.run(ARGV)
|
data/lib/multiple_man.rb
CHANGED
@@ -4,7 +4,7 @@ require 'active_support'
|
|
4
4
|
module MultipleMan
|
5
5
|
Error = Class.new(StandardError)
|
6
6
|
ConsumerError = Class.new(Error)
|
7
|
-
|
7
|
+
|
8
8
|
require 'multiple_man/railtie' if defined?(Rails)
|
9
9
|
|
10
10
|
require 'multiple_man/mixins/publisher'
|
@@ -25,6 +25,8 @@ module MultipleMan
|
|
25
25
|
require 'multiple_man/model_populator'
|
26
26
|
require 'multiple_man/identity'
|
27
27
|
require 'multiple_man/publish'
|
28
|
+
require 'multiple_man/runner'
|
29
|
+
require 'multiple_man/cli'
|
28
30
|
|
29
31
|
require 'multiple_man/channel_maintenance/gc'
|
30
32
|
require 'multiple_man/channel_maintenance/reaper'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module MultipleMan
|
4
|
+
class Options < OptionParser
|
5
|
+
def self.parse!(args)
|
6
|
+
parser = new('Multiple Man')
|
7
|
+
parser.set_opts.parse!(args)
|
8
|
+
parser.options
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :options
|
12
|
+
|
13
|
+
def initialize(*args)
|
14
|
+
@options = { mode: :general, environment_path: 'config/environment' }
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_opts
|
19
|
+
on('--seed', 'listen to the seeding queue') do
|
20
|
+
options[:mode] == :seed
|
21
|
+
end
|
22
|
+
on('-e', '--environment-path PATH', 'Set the path to load the web framework (default: config/environment)') do |value|
|
23
|
+
options[:environment_path] = value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module CLI
|
29
|
+
module_function
|
30
|
+
|
31
|
+
def run(args)
|
32
|
+
options = Options.parse!(args)
|
33
|
+
|
34
|
+
require options[:environment_path]
|
35
|
+
|
36
|
+
Runner.new(mode: options[:mode]).run
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module MultipleMan
|
4
|
+
def self.trap_signals!
|
5
|
+
return if @signals_trapped
|
6
|
+
|
7
|
+
@signals_trapped = true
|
8
|
+
|
9
|
+
handler = proc do |signal|
|
10
|
+
puts "received #{Signal.signame(signal)}"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
%w(INT QUIT TERM).each { |signal| Signal.trap(signal, handler) }
|
15
|
+
end
|
16
|
+
|
17
|
+
class Runner
|
18
|
+
extend Forwardable
|
19
|
+
|
20
|
+
MODES = [:general, :seed].freeze
|
21
|
+
|
22
|
+
def initialize(options = {})
|
23
|
+
@mode = options.fetch(:mode, :general)
|
24
|
+
|
25
|
+
raise ArgumentError, "undefined mode: #{mode}" unless MODES.include?(mode)
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
MultipleMan.trap_signals!
|
30
|
+
preload_framework!
|
31
|
+
channel.prefetch(prefetch_size)
|
32
|
+
build_listener.listen
|
33
|
+
sleep
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :mode
|
39
|
+
|
40
|
+
def_delegators :config, :prefetch_size, :queue_name, :listeners, :topic_name
|
41
|
+
|
42
|
+
def preload_framework!
|
43
|
+
Rails.application.eager_load! if defined?(Rails)
|
44
|
+
Hanami::Application.preload_applications! if defined?(Hanami)
|
45
|
+
end
|
46
|
+
|
47
|
+
def build_listener
|
48
|
+
listener_class.new(
|
49
|
+
queue: channel.queue(*queue_params),
|
50
|
+
subscribers: listeners,
|
51
|
+
topic: topic_name
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def listener_class
|
56
|
+
if seeding?
|
57
|
+
Consumers::Seed
|
58
|
+
else
|
59
|
+
Consumers::General
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def queue_params
|
64
|
+
if seeding?
|
65
|
+
["#{queue_name}.seed", durable: false, auto_delete: true]
|
66
|
+
else
|
67
|
+
[queue_name, durable: true, auto_delete: false]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def channel
|
72
|
+
@channel ||= Connection.connection.create_channel
|
73
|
+
end
|
74
|
+
|
75
|
+
def config
|
76
|
+
MultipleMan.configuration
|
77
|
+
end
|
78
|
+
|
79
|
+
def seeding?
|
80
|
+
mode == :seed
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -1,37 +1,12 @@
|
|
1
1
|
namespace :multiple_man do
|
2
|
-
desc
|
2
|
+
desc 'Run multiple man listeners'
|
3
3
|
task worker: :environment do
|
4
|
-
|
5
|
-
channel.prefetch(MultipleMan.configuration.prefetch_size)
|
6
|
-
queue_name = MultipleMan.configuration.queue_name
|
7
|
-
queue = channel.queue(queue_name, durable: true, auto_delete: false)
|
8
|
-
|
9
|
-
run_listener(MultipleMan::Consumers::General, queue)
|
4
|
+
MultipleMan::Runner.new(mode: :general).run
|
10
5
|
end
|
11
6
|
|
12
7
|
desc 'Run a seeding listener'
|
13
8
|
task seed: :environment do
|
14
|
-
|
15
|
-
channel.prefetch(MultipleMan.configuration.prefetch_size)
|
16
|
-
queue_name = MultipleMan.configuration.queue_name + '.seed'
|
17
|
-
queue = channel.queue(queue_name, durable: false, auto_delete: true)
|
18
|
-
|
19
|
-
run_listener(MultipleMan::Consumers::Seed, queue)
|
20
|
-
end
|
21
|
-
|
22
|
-
def run_listener(listener, queue)
|
23
|
-
Rails.application.eager_load! if defined?(Rails)
|
24
|
-
|
25
|
-
subscribers = MultipleMan.configuration.listeners
|
26
|
-
topic = MultipleMan.configuration.topic_name
|
27
|
-
|
28
|
-
listener.new(subscribers: subscribers, queue: queue, topic: topic).listen
|
29
|
-
|
30
|
-
Signal.trap("INT") { puts "received INT"; exit }
|
31
|
-
Signal.trap("QUIT") { puts "received QUIT"; exit }
|
32
|
-
Signal.trap("TERM") { puts "received TERM"; exit }
|
33
|
-
|
34
|
-
sleep
|
9
|
+
MultipleMan::Runner.new(mode: :seed).run
|
35
10
|
end
|
36
11
|
|
37
12
|
desc 'Run transitional worker'
|
@@ -54,10 +29,7 @@ namespace :multiple_man do
|
|
54
29
|
MultipleMan::Consumers::Transitional.new(subscription: listener, queue: queue, topic: topic).listen
|
55
30
|
end
|
56
31
|
|
57
|
-
|
58
|
-
Signal.trap("QUIT") { puts "received QUIT"; exit }
|
59
|
-
Signal.trap("TERM") { puts "received TERM"; exit }
|
60
|
-
|
32
|
+
MultipleMan.trap_signals!
|
61
33
|
sleep
|
62
34
|
end
|
63
35
|
|
data/lib/multiple_man/version.rb
CHANGED
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.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Brunner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -139,7 +139,8 @@ dependencies:
|
|
139
139
|
description: MultipleMan syncs changes to ActiveRecord models via AMQP
|
140
140
|
email:
|
141
141
|
- ryan@influitive.com
|
142
|
-
executables:
|
142
|
+
executables:
|
143
|
+
- multiple_man
|
143
144
|
extensions: []
|
144
145
|
extra_rdoc_files: []
|
145
146
|
files:
|
@@ -150,11 +151,13 @@ files:
|
|
150
151
|
- LICENSE.txt
|
151
152
|
- README.md
|
152
153
|
- Rakefile
|
154
|
+
- bin/multiple_man
|
153
155
|
- circle.yml
|
154
156
|
- lib/multiple_man.rb
|
155
157
|
- lib/multiple_man/attribute_extractor.rb
|
156
158
|
- lib/multiple_man/channel_maintenance/gc.rb
|
157
159
|
- lib/multiple_man/channel_maintenance/reaper.rb
|
160
|
+
- lib/multiple_man/cli.rb
|
158
161
|
- lib/multiple_man/configuration.rb
|
159
162
|
- lib/multiple_man/connection.rb
|
160
163
|
- lib/multiple_man/consumers/general.rb
|
@@ -170,6 +173,7 @@ files:
|
|
170
173
|
- lib/multiple_man/publish.rb
|
171
174
|
- lib/multiple_man/railtie.rb
|
172
175
|
- lib/multiple_man/routing_key.rb
|
176
|
+
- lib/multiple_man/runner.rb
|
173
177
|
- lib/multiple_man/subscribers/base.rb
|
174
178
|
- lib/multiple_man/subscribers/model_subscriber.rb
|
175
179
|
- lib/multiple_man/subscribers/registry.rb
|