sanger_warren 0.1.0 → 0.2.0.rc1
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/.github/workflows/ruby.yml +39 -0
- data/.rubocop.yml +11 -5
- data/CHANGELOG.md +9 -1
- data/Gemfile +6 -1
- data/Gemfile.lock +68 -36
- data/README.md +105 -44
- data/bin/console +3 -6
- data/bin/warren +6 -0
- data/lefthook.yml +53 -0
- data/lib/sanger_warren.rb +8 -0
- data/lib/warren.rb +49 -4
- data/lib/warren/app.rb +9 -0
- data/lib/warren/app/cli.rb +34 -0
- data/lib/warren/app/config.rb +100 -0
- data/lib/warren/app/consumer.rb +53 -0
- data/lib/warren/app/consumer_add.rb +122 -0
- data/lib/warren/app/consumer_start.rb +25 -0
- data/lib/warren/app/exchange_config.rb +138 -0
- data/lib/warren/app/templates/subscriber.tt +32 -0
- data/lib/warren/callback.rb +2 -7
- data/lib/warren/client.rb +111 -0
- data/lib/warren/config/consumers.rb +101 -0
- data/lib/warren/den.rb +77 -0
- data/lib/warren/exceptions.rb +15 -0
- data/lib/warren/fox.rb +161 -0
- data/lib/warren/framework_adaptor/rails_adaptor.rb +83 -0
- data/lib/warren/handler/base.rb +20 -0
- data/lib/warren/handler/broadcast.rb +30 -16
- data/lib/warren/handler/log.rb +42 -10
- data/lib/warren/handler/test.rb +102 -14
- data/lib/warren/helpers/state_machine.rb +55 -0
- data/lib/warren/log_tagger.rb +58 -0
- data/lib/warren/message.rb +5 -5
- data/lib/warren/message/short.rb +41 -4
- data/lib/warren/railtie.rb +12 -0
- data/lib/warren/subscriber/base.rb +123 -0
- data/lib/warren/subscription.rb +71 -0
- data/lib/warren/version.rb +2 -1
- data/sanger-warren.gemspec +5 -4
- metadata +48 -8
- data/.travis.yml +0 -6
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Warren
|
4
|
+
# Configures and wraps up subscriptions on a Bunny Channel/Queue
|
5
|
+
class Subscription
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
attr_reader :channel
|
9
|
+
|
10
|
+
#
|
11
|
+
# Great a new subscription. Handles queue creation, binding and attaching
|
12
|
+
# consumers to the queues
|
13
|
+
#
|
14
|
+
# @param channel [Warren::Handler::Broadcast::Channel] A chanel on which to register queues
|
15
|
+
# @param config [Hash] queue configuration hash
|
16
|
+
#
|
17
|
+
def initialize(channel:, config:)
|
18
|
+
@channel = channel
|
19
|
+
@queue_name = config.fetch('name')
|
20
|
+
@queue_options = config.fetch('options')
|
21
|
+
@bindings = config.fetch('bindings')
|
22
|
+
end
|
23
|
+
|
24
|
+
def_delegators :channel, :nack, :ack
|
25
|
+
|
26
|
+
#
|
27
|
+
# Subscribes to the given queue
|
28
|
+
#
|
29
|
+
# @param consumer_tag [String] Identifier for the consumer
|
30
|
+
#
|
31
|
+
# @yieldparam [Bunny::DeliveryInfo] delivery_info Metadata about the delivery
|
32
|
+
# @yieldparam [Bunny::MessageProperties] properties
|
33
|
+
# @yieldparam [String] payload the contents of the message
|
34
|
+
#
|
35
|
+
# @return [Bunny::Consumer] The bunny consumer object
|
36
|
+
#
|
37
|
+
def subscribe(consumer_tag, &block)
|
38
|
+
channel.prefetch(10)
|
39
|
+
queue.subscribe(manual_ack: true, block: false, consumer_tag: consumer_tag, durable: true, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Ensures the queues and channels are set up to receive messages
|
43
|
+
# keys: additional routing_keys to bind
|
44
|
+
def activate!
|
45
|
+
establish_bindings!
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def add_binding(exchange, options)
|
51
|
+
queue.bind(exchange, options)
|
52
|
+
end
|
53
|
+
|
54
|
+
def exchange(config)
|
55
|
+
channel.exchange(*config.values_at('name', 'options'))
|
56
|
+
end
|
57
|
+
|
58
|
+
def queue
|
59
|
+
raise StandardError, 'No queue configured' if @queue_name.nil?
|
60
|
+
|
61
|
+
channel.queue(@queue_name, @queue_options)
|
62
|
+
end
|
63
|
+
|
64
|
+
def establish_bindings!
|
65
|
+
@bindings.each do |binding_config|
|
66
|
+
exchange = exchange(binding_config['exchange'])
|
67
|
+
add_binding(exchange, binding_config['options'])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/warren/version.rb
CHANGED
data/sanger-warren.gemspec
CHANGED
@@ -15,24 +15,25 @@ Gem::Specification.new do |spec|
|
|
15
15
|
DESCRIPTION
|
16
16
|
spec.homepage = 'https://github.com/sanger/warren'
|
17
17
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
18
|
-
|
19
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
18
|
+
spec.license = 'GPL'
|
20
19
|
|
21
20
|
spec.metadata['homepage_uri'] = spec.homepage
|
22
21
|
spec.metadata['source_code_uri'] = 'https://github.com/sanger/warren'
|
23
22
|
spec.metadata['changelog_uri'] = 'https://github.com/sanger/warren/blob/master/CHANGELOG.md'
|
23
|
+
spec.metadata['documentation_uri'] = 'https://rubydoc.info/gems/sanger_warren'
|
24
24
|
|
25
25
|
# Specify which files should be added to the gem when it is released.
|
26
26
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
27
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
28
28
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
29
|
end
|
30
|
-
spec.bindir
|
31
|
-
spec.executables
|
30
|
+
spec.bindir = 'bin'
|
31
|
+
spec.executables << 'warren'
|
32
32
|
spec.require_paths = ['lib']
|
33
33
|
|
34
34
|
# Dependencies
|
35
35
|
spec.add_runtime_dependency 'bunny', '~> 2.17.0'
|
36
36
|
spec.add_runtime_dependency 'connection_pool', '~> 2.2.0'
|
37
37
|
spec.add_runtime_dependency 'multi_json', '~> 1.0'
|
38
|
+
spec.add_runtime_dependency 'thor', '~> 1.1.0'
|
38
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanger_warren
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Glover
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -52,19 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.1.0
|
55
69
|
description: |
|
56
70
|
Warren provides connection pooling for RabbitMQ connections. It also adds
|
57
71
|
the ability to switch in different adapters during testing and development.
|
58
72
|
email:
|
59
73
|
- james.glover@sanger.ac.uk
|
60
|
-
executables:
|
74
|
+
executables:
|
75
|
+
- warren
|
61
76
|
extensions: []
|
62
77
|
extra_rdoc_files: []
|
63
78
|
files:
|
79
|
+
- ".github/workflows/ruby.yml"
|
64
80
|
- ".gitignore"
|
65
81
|
- ".rspec"
|
66
82
|
- ".rubocop.yml"
|
67
|
-
- ".travis.yml"
|
68
83
|
- CHANGELOG.md
|
69
84
|
- Gemfile
|
70
85
|
- Gemfile.lock
|
@@ -73,30 +88,55 @@ files:
|
|
73
88
|
- Rakefile
|
74
89
|
- bin/console
|
75
90
|
- bin/setup
|
91
|
+
- bin/warren
|
76
92
|
- checksums
|
77
93
|
- complete
|
94
|
+
- lefthook.yml
|
95
|
+
- lib/sanger_warren.rb
|
78
96
|
- lib/warren.rb
|
97
|
+
- lib/warren/app.rb
|
98
|
+
- lib/warren/app/cli.rb
|
99
|
+
- lib/warren/app/config.rb
|
100
|
+
- lib/warren/app/consumer.rb
|
101
|
+
- lib/warren/app/consumer_add.rb
|
102
|
+
- lib/warren/app/consumer_start.rb
|
103
|
+
- lib/warren/app/exchange_config.rb
|
104
|
+
- lib/warren/app/templates/subscriber.tt
|
79
105
|
- lib/warren/callback.rb
|
80
106
|
- lib/warren/callback/broadcast_associated_with_warren.rb
|
81
107
|
- lib/warren/callback/broadcast_with_warren.rb
|
108
|
+
- lib/warren/client.rb
|
109
|
+
- lib/warren/config/consumers.rb
|
110
|
+
- lib/warren/den.rb
|
111
|
+
- lib/warren/exceptions.rb
|
112
|
+
- lib/warren/fox.rb
|
113
|
+
- lib/warren/framework_adaptor/rails_adaptor.rb
|
82
114
|
- lib/warren/handler.rb
|
115
|
+
- lib/warren/handler/base.rb
|
83
116
|
- lib/warren/handler/broadcast.rb
|
84
117
|
- lib/warren/handler/log.rb
|
85
118
|
- lib/warren/handler/test.rb
|
119
|
+
- lib/warren/helpers/state_machine.rb
|
120
|
+
- lib/warren/log_tagger.rb
|
86
121
|
- lib/warren/message.rb
|
87
122
|
- lib/warren/message/full.rb
|
88
123
|
- lib/warren/message/short.rb
|
124
|
+
- lib/warren/railtie.rb
|
125
|
+
- lib/warren/subscriber/base.rb
|
126
|
+
- lib/warren/subscription.rb
|
89
127
|
- lib/warren/version.rb
|
90
128
|
- object_types
|
91
129
|
- objects/root.dat
|
92
130
|
- proxy_types
|
93
131
|
- sanger-warren.gemspec
|
94
132
|
homepage: https://github.com/sanger/warren
|
95
|
-
licenses:
|
133
|
+
licenses:
|
134
|
+
- GPL
|
96
135
|
metadata:
|
97
136
|
homepage_uri: https://github.com/sanger/warren
|
98
137
|
source_code_uri: https://github.com/sanger/warren
|
99
138
|
changelog_uri: https://github.com/sanger/warren/blob/master/CHANGELOG.md
|
139
|
+
documentation_uri: https://rubydoc.info/gems/sanger_warren
|
100
140
|
post_install_message:
|
101
141
|
rdoc_options: []
|
102
142
|
require_paths:
|
@@ -108,9 +148,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
148
|
version: 2.6.0
|
109
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
150
|
requirements:
|
111
|
-
- - "
|
151
|
+
- - ">"
|
112
152
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
153
|
+
version: 1.3.1
|
114
154
|
requirements: []
|
115
155
|
rubygems_version: 3.1.4
|
116
156
|
signing_key:
|