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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6f14e9809f8c71405a3696920321ebbf7477c7f0ecf05421a3ffd85f4fbccfc
|
4
|
+
data.tar.gz: 5e13bbba217f9b09ad08433178e03f822a6f97e207c80e532a5c8b15c8d36b7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e2966ea368981ab85de2fc6ed22e349af14f2178862ee0025c79699a494e1d857d96eb23ab1c5fe5a68a24c9f6db68254c488add1d181b9391dc6e17156ca32
|
7
|
+
data.tar.gz: 8e882eba3c9a5e450447c73784bbed94655bf599c086521c0298a3f9a45433fca703ac52660644b262d837b94f0e793f3393e461dc62d96e76b99cffb1c64a6b
|
@@ -0,0 +1,39 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
- push
|
5
|
+
- pull_request
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test:
|
9
|
+
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.6', '2.7', '3.0' ]
|
14
|
+
name: Ruby Test ${{ matrix.ruby }}
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
bundler-cache: true # Runs bundle install and caches gems. See the ruby_test.yml
|
23
|
+
# example if you need more control over bundler.
|
24
|
+
- name: Run tests
|
25
|
+
run: bundle exec rake
|
26
|
+
lint:
|
27
|
+
|
28
|
+
runs-on: ubuntu-latest
|
29
|
+
|
30
|
+
steps:
|
31
|
+
- uses: actions/checkout@v2
|
32
|
+
- name: Set up Ruby
|
33
|
+
uses: ruby/setup-ruby@v1
|
34
|
+
with:
|
35
|
+
ruby-version: 3.0
|
36
|
+
bundler-cache: true # Runs bundle install and caches gems. See the ruby_test.yml
|
37
|
+
# example if you need more control over bundler.
|
38
|
+
- name: Run lint
|
39
|
+
run: bundle exec rubocop
|
data/.rubocop.yml
CHANGED
@@ -8,14 +8,20 @@
|
|
8
8
|
# where the inspected file is and continue its way up to the root directory.
|
9
9
|
#
|
10
10
|
# See https://docs.rubocop.org/rubocop/configuration
|
11
|
+
require:
|
12
|
+
- rubocop-rake
|
13
|
+
- rubocop-rspec
|
14
|
+
|
11
15
|
AllCops:
|
12
16
|
TargetRubyVersion: 2.6
|
17
|
+
NewCops: enable
|
13
18
|
# Blocks are used to structure tests and are part of the shoulda dsl.
|
14
19
|
# The standard BlockLength limits are too stringent for this purpose.
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# Not sure if we need to split namespaces across several files though.
|
18
|
-
# We exclude builders, as they are concerned with rendering xml
|
20
|
+
# We also disable it for the gemspec, as while its using new, its more like
|
21
|
+
# a DSL in nature
|
19
22
|
Metrics/BlockLength:
|
20
|
-
|
23
|
+
Exclude:
|
24
|
+
- '*.gemspec'
|
25
|
+
IgnoredMethods:
|
21
26
|
- describe
|
27
|
+
- context
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,14 @@ Unreleased section to make new releases easy.
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
-
|
8
|
+
### Added
|
9
|
+
|
10
|
+
- Added railties to automatically initialize and configure Warren in rails apps.
|
11
|
+
You can remove the `config/initializers/warren.rb` and the `config.warren = config_for(:warren)`
|
12
|
+
line from `config/application.rb`
|
13
|
+
- Added `warren config` CLI to help generate a warren.yml configuration file.
|
14
|
+
- Added warren consumers managed through `warren consumer`
|
15
|
+
|
16
|
+
## Initial release
|
9
17
|
|
10
18
|
- Import of lib/warren from sequencescape
|
data/Gemfile
CHANGED
@@ -6,8 +6,13 @@ source 'https://rubygems.org'
|
|
6
6
|
gemspec
|
7
7
|
|
8
8
|
gem 'pry'
|
9
|
-
gem 'rake', '~>
|
9
|
+
gem 'rake', '~> 13.0'
|
10
10
|
gem 'rspec', '~> 3.0'
|
11
11
|
gem 'rubocop'
|
12
|
+
gem 'rubocop-rake'
|
13
|
+
gem 'rubocop-rspec'
|
12
14
|
gem 'simplecov'
|
13
15
|
gem 'yard'
|
16
|
+
|
17
|
+
# Used to provide instance_doubles for more robust testing
|
18
|
+
gem 'activerecord', '~>5.2.0', require: false
|
data/Gemfile.lock
CHANGED
@@ -1,77 +1,109 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sanger_warren (0.
|
4
|
+
sanger_warren (0.2.0.rc1)
|
5
5
|
bunny (~> 2.17.0)
|
6
6
|
connection_pool (~> 2.2.0)
|
7
7
|
multi_json (~> 1.0)
|
8
|
+
thor (~> 1.1.0)
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
13
|
+
activemodel (5.2.5)
|
14
|
+
activesupport (= 5.2.5)
|
15
|
+
activerecord (5.2.5)
|
16
|
+
activemodel (= 5.2.5)
|
17
|
+
activesupport (= 5.2.5)
|
18
|
+
arel (>= 9.0)
|
19
|
+
activesupport (5.2.5)
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
+
i18n (>= 0.7, < 2)
|
22
|
+
minitest (~> 5.1)
|
23
|
+
tzinfo (~> 1.1)
|
12
24
|
amq-protocol (2.3.2)
|
13
|
-
|
25
|
+
arel (9.0.0)
|
26
|
+
ast (2.4.2)
|
14
27
|
bunny (2.17.0)
|
15
28
|
amq-protocol (~> 2.3, >= 2.3.1)
|
16
|
-
coderay (1.1.
|
29
|
+
coderay (1.1.3)
|
30
|
+
concurrent-ruby (1.1.8)
|
17
31
|
connection_pool (2.2.3)
|
18
32
|
diff-lcs (1.4.4)
|
19
|
-
docile (1.3.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
33
|
+
docile (1.3.5)
|
34
|
+
i18n (1.8.10)
|
35
|
+
concurrent-ruby (~> 1.0)
|
36
|
+
method_source (1.0.0)
|
37
|
+
minitest (5.14.4)
|
38
|
+
multi_json (1.15.0)
|
39
|
+
parallel (1.20.1)
|
40
|
+
parser (3.0.0.0)
|
24
41
|
ast (~> 2.4.1)
|
25
|
-
pry (0.
|
26
|
-
coderay (~> 1.1
|
27
|
-
method_source (~>
|
42
|
+
pry (0.14.0)
|
43
|
+
coderay (~> 1.1)
|
44
|
+
method_source (~> 1.0)
|
28
45
|
rainbow (3.0.0)
|
29
|
-
rake (
|
30
|
-
regexp_parser (1.
|
46
|
+
rake (13.0.3)
|
47
|
+
regexp_parser (2.1.1)
|
31
48
|
rexml (3.2.4)
|
32
|
-
rspec (3.
|
33
|
-
rspec-core (~> 3.
|
34
|
-
rspec-expectations (~> 3.
|
35
|
-
rspec-mocks (~> 3.
|
36
|
-
rspec-core (3.
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-expectations (3.
|
49
|
+
rspec (3.10.0)
|
50
|
+
rspec-core (~> 3.10.0)
|
51
|
+
rspec-expectations (~> 3.10.0)
|
52
|
+
rspec-mocks (~> 3.10.0)
|
53
|
+
rspec-core (3.10.1)
|
54
|
+
rspec-support (~> 3.10.0)
|
55
|
+
rspec-expectations (3.10.1)
|
39
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.
|
41
|
-
rspec-mocks (3.
|
57
|
+
rspec-support (~> 3.10.0)
|
58
|
+
rspec-mocks (3.10.2)
|
42
59
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-support (3.
|
45
|
-
rubocop (1.
|
60
|
+
rspec-support (~> 3.10.0)
|
61
|
+
rspec-support (3.10.2)
|
62
|
+
rubocop (1.11.0)
|
46
63
|
parallel (~> 1.10)
|
47
|
-
parser (>=
|
64
|
+
parser (>= 3.0.0.0)
|
48
65
|
rainbow (>= 2.2.2, < 4.0)
|
49
|
-
regexp_parser (>= 1.8)
|
66
|
+
regexp_parser (>= 1.8, < 3.0)
|
50
67
|
rexml
|
51
|
-
rubocop-ast (>=
|
68
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
52
69
|
ruby-progressbar (~> 1.7)
|
53
|
-
unicode-display_width (>= 1.4.0, <
|
54
|
-
rubocop-ast (1.
|
70
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
71
|
+
rubocop-ast (1.4.1)
|
55
72
|
parser (>= 2.7.1.5)
|
56
|
-
|
57
|
-
|
73
|
+
rubocop-rake (0.5.1)
|
74
|
+
rubocop
|
75
|
+
rubocop-rspec (2.2.0)
|
76
|
+
rubocop (~> 1.0)
|
77
|
+
rubocop-ast (>= 1.1.0)
|
78
|
+
ruby-progressbar (1.11.0)
|
79
|
+
simplecov (0.21.2)
|
58
80
|
docile (~> 1.1)
|
59
81
|
simplecov-html (~> 0.11)
|
82
|
+
simplecov_json_formatter (~> 0.1)
|
60
83
|
simplecov-html (0.12.3)
|
61
|
-
|
62
|
-
|
84
|
+
simplecov_json_formatter (0.1.2)
|
85
|
+
thor (1.1.0)
|
86
|
+
thread_safe (0.3.6)
|
87
|
+
tzinfo (1.2.9)
|
88
|
+
thread_safe (~> 0.1)
|
89
|
+
unicode-display_width (2.0.0)
|
90
|
+
yard (0.9.26)
|
63
91
|
|
64
92
|
PLATFORMS
|
65
93
|
ruby
|
94
|
+
x86_64-darwin-19
|
66
95
|
|
67
96
|
DEPENDENCIES
|
97
|
+
activerecord (~> 5.2.0)
|
68
98
|
pry
|
69
|
-
rake (~>
|
99
|
+
rake (~> 13.0)
|
70
100
|
rspec (~> 3.0)
|
71
101
|
rubocop
|
102
|
+
rubocop-rake
|
103
|
+
rubocop-rspec
|
72
104
|
sanger_warren!
|
73
105
|
simplecov
|
74
106
|
yard
|
75
107
|
|
76
108
|
BUNDLED WITH
|
77
|
-
2.
|
109
|
+
2.2.8
|
data/README.md
CHANGED
@@ -14,68 +14,129 @@ gem 'sanger-warren'
|
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
17
|
-
|
17
|
+
```bash
|
18
|
+
bundle install
|
19
|
+
```
|
18
20
|
|
19
21
|
Or install it yourself as:
|
20
22
|
|
21
|
-
|
23
|
+
```bash
|
24
|
+
gem install sanger_warren
|
25
|
+
```
|
22
26
|
|
23
27
|
## Usage
|
24
28
|
|
25
|
-
|
29
|
+
### Basic setup
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
If using with a Rails app, you can simply run `bundle exec warren config` to
|
32
|
+
help generate a warren config file. Warren will automatically be initialize
|
33
|
+
on Rails start-up.
|
34
|
+
|
35
|
+
### Handler types
|
36
|
+
|
37
|
+
In development mode, warren is usually configured to log to the console only. If
|
38
|
+
you wish to enable broadcast mode, the easiest way is via an environmental
|
39
|
+
variable, WARREN_TYPE.
|
30
40
|
|
31
|
-
|
41
|
+
```bash
|
42
|
+
WARREN_TYPE=broadcast bundle exec rails s
|
32
43
|
```
|
33
44
|
|
45
|
+
### Broadcasting a message
|
46
|
+
|
47
|
+
To broadcast a message, simply push the message onto the message handler
|
48
|
+
|
34
49
|
```ruby
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
50
|
+
Warren.handler << message
|
51
|
+
```
|
52
|
+
|
53
|
+
Message should be an object that responds to routing_key and payload. The handler
|
54
|
+
will automatically prefix the routing key with the 'routing_key_prefix' configured
|
55
|
+
in the warren.yml file. By default this is usually the name of your environment.
|
56
|
+
|
57
|
+
If you are sending out multiple messages, you can check out a channel from the
|
58
|
+
connection pool, and use that instead.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
Warren.handler.with_channel do |channel|
|
62
|
+
channel << message_a
|
63
|
+
channel << message_b
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
### Setting up a consumer
|
68
|
+
|
69
|
+
A command line interface exists to assist with setting up consumers. It be be
|
70
|
+
invoked with:
|
71
|
+
|
72
|
+
```bash
|
73
|
+
bundle exec warren consumer add
|
74
|
+
```
|
75
|
+
|
76
|
+
This will guide you through configuration, and template out a subscriber class.
|
77
|
+
Subscribers receive the message payload, and metadata information and process
|
78
|
+
them in their #process method.
|
79
|
+
|
80
|
+
For more information about optional command line arguments you can supply to
|
81
|
+
the cli use:
|
82
|
+
|
83
|
+
```bash
|
84
|
+
bundle exec warren consumer add --help
|
39
85
|
```
|
40
86
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
config: # Useful to allow easy switching to broadcast
|
61
|
-
routing_key_prefix: 'production'
|
62
|
-
server:
|
63
|
-
host: localhost # Or a remote host
|
64
|
-
port: 5672
|
65
|
-
username: ...
|
66
|
-
password: ...
|
67
|
-
vhost: /
|
68
|
-
frame_max: 0
|
69
|
-
heartbeat: 30
|
70
|
-
exchange: exchange_to_use
|
87
|
+
#### Opinionated defaults
|
88
|
+
|
89
|
+
The cli makes some opinionated assumptions to simplify setup process:
|
90
|
+
|
91
|
+
- Consumers will use a subscriber class named Warren::Subscribed::CamelCasedConsumerName
|
92
|
+
- All consumers will dead-letter to the fanout exchange consumer-name.dead_letters
|
93
|
+
- consumer-name.dead_letters will be bound to a queue of the same name
|
94
|
+
- All queues and exchanges are durable
|
95
|
+
|
96
|
+
These options can be over-ridden in the warren_consumers.yml file if necessary.
|
97
|
+
If you wish to completely disable dead-letter queue configuration, such as when
|
98
|
+
using policies, then you can set dead_letters to false.
|
99
|
+
|
100
|
+
### Running consumers
|
101
|
+
|
102
|
+
To run all configure consumers use:
|
103
|
+
|
104
|
+
```bash
|
105
|
+
bundle exec warren consumer start
|
71
106
|
```
|
72
107
|
|
108
|
+
You can also run only a subset of consumers:
|
109
|
+
|
110
|
+
```bash
|
111
|
+
bundle exec warren consumer start --consumers=consumer_name other_consumer
|
112
|
+
```
|
113
|
+
|
114
|
+
If you are testing in development, don't forget to set the WARREN_TYPE
|
115
|
+
environmental variable if you want to pull messages off an actual queue.
|
116
|
+
|
117
|
+
```bash
|
118
|
+
WARREN_TYPE=broadcast bundle exec warren consumer start
|
119
|
+
```
|
120
|
+
|
121
|
+
## Testing
|
122
|
+
|
123
|
+
Warren provides useful helpers to assist with testing. Helper documentation, and
|
124
|
+
some testing examples can be found in the documentation for the
|
125
|
+
{Warren::Handler::Test test helper}, or online at
|
126
|
+
[rubydoc.info](https://rubydoc.info/gems/sanger_warren/Warren/Handler/Test)
|
127
|
+
|
73
128
|
## Development
|
74
129
|
|
75
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
130
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
131
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
132
|
+
prompt that will allow you to experiment.
|
76
133
|
|
77
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
134
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
135
|
+
release a new version, update the version number in `version.rb`, and then run
|
136
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
137
|
+
git commits and tags, and push the `.gem` file to
|
138
|
+
[rubygems.org](https://rubygems.org).
|
78
139
|
|
79
140
|
## Contributing
|
80
141
|
|
81
|
-
Bug reports and pull requests are welcome on GitHub
|
142
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/sanger/warren)
|
data/bin/console
CHANGED
@@ -2,14 +2,11 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'bundler/setup'
|
5
|
-
require '
|
5
|
+
require 'warren'
|
6
6
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
9
9
|
|
10
10
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
require 'irb'
|
15
|
-
IRB.start(__FILE__)
|
11
|
+
require 'pry'
|
12
|
+
Pry.start
|