sanger_warren 0.1.0 → 0.3.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +39 -0
  3. data/.rubocop.yml +11 -5
  4. data/.yardopts +3 -0
  5. data/CHANGELOG.md +34 -1
  6. data/Gemfile +6 -1
  7. data/Gemfile.lock +71 -39
  8. data/README.md +133 -43
  9. data/bin/console +3 -6
  10. data/bin/warren +6 -0
  11. data/lefthook.yml +53 -0
  12. data/lib/sanger_warren.rb +8 -0
  13. data/lib/warren.rb +49 -4
  14. data/lib/warren/app.rb +9 -0
  15. data/lib/warren/app/cli.rb +35 -0
  16. data/lib/warren/app/config.rb +110 -0
  17. data/lib/warren/app/consumer.rb +65 -0
  18. data/lib/warren/app/consumer_add.rb +131 -0
  19. data/lib/warren/app/consumer_start.rb +40 -0
  20. data/lib/warren/app/exchange_config.rb +151 -0
  21. data/lib/warren/app/templates/subscriber.tt +32 -0
  22. data/lib/warren/callback.rb +2 -7
  23. data/lib/warren/callback/broadcast_with_warren.rb +1 -1
  24. data/lib/warren/client.rb +111 -0
  25. data/lib/warren/config/consumers.rb +123 -0
  26. data/lib/warren/delay_exchange.rb +85 -0
  27. data/lib/warren/den.rb +93 -0
  28. data/lib/warren/exceptions.rb +15 -0
  29. data/lib/warren/fox.rb +165 -0
  30. data/lib/warren/framework_adaptor/rails_adaptor.rb +135 -0
  31. data/lib/warren/handler.rb +16 -0
  32. data/lib/warren/handler/base.rb +20 -0
  33. data/lib/warren/handler/broadcast.rb +54 -18
  34. data/lib/warren/handler/log.rb +50 -10
  35. data/lib/warren/handler/test.rb +101 -14
  36. data/lib/warren/helpers/state_machine.rb +55 -0
  37. data/lib/warren/log_tagger.rb +58 -0
  38. data/lib/warren/message.rb +7 -5
  39. data/lib/warren/message/full.rb +20 -0
  40. data/lib/warren/message/short.rb +49 -4
  41. data/lib/warren/message/simple.rb +15 -0
  42. data/lib/warren/railtie.rb +12 -0
  43. data/lib/warren/subscriber/base.rb +151 -0
  44. data/lib/warren/subscription.rb +78 -0
  45. data/lib/warren/version.rb +2 -1
  46. data/sanger-warren.gemspec +5 -4
  47. metadata +49 -6
  48. data/.travis.yml +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08237db3ed2d846148e3e1b127b737d660cb48f755489ced7fbda20d582fb3c2'
4
- data.tar.gz: 41dc24f4262cc1b641e985058d7ef6b1cb294ef9e26c42775ac68bd21182c8e3
3
+ metadata.gz: 07d40b65d949f1c9fe0a1622faab1cfc6e64483ef498400daae60d7dd17d4897
4
+ data.tar.gz: badadcd8587f75dd72cc240df07947a39a222741043525ed204efb7738b13511
5
5
  SHA512:
6
- metadata.gz: e60a34f8902db181b06978f0b554485c8f69148e9111b2a325ad6b37b13dc4abef93f5e8d010ad4e2d2d7dab4dcdfddfa51f6b5fe5866e037d9d437e85095af2
7
- data.tar.gz: 98a52f7cdfaf2815f6b83a5166791bb83ab84aaa37e87ed9b4d68534fccb7a9efe14ec0c618467bd24f8c67deecd2124833245b0e3bc7b156ca48ff2a4762bb6
6
+ metadata.gz: 333c5cb6382e1ac5cdf475a66e541afcaa0ca5698105cf8e62d435c8bbf2171e59f165875597d507c75b2b8a4eff8504a96f7d6295cf24f05a5393ac55c01716
7
+ data.tar.gz: de3d17ae3bdeaf272ca52a3f5170187efb570709ca77f77a657221400d1fcf50706d8d48c6aa48118bfb3f67276925412baaf4fe7fb250ef64abe1da02134267
@@ -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
- # Block DSL is also used in routes
16
- # We should be careful keeping rake tasks here, as large tasks are still an issue.
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
- ExcludedMethods:
23
+ Exclude:
24
+ - '*.gemspec'
25
+ IgnoredMethods:
21
26
  - describe
27
+ - context
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ -
2
+ LICENSE.txt
3
+ CHANGELOG.md
data/CHANGELOG.md CHANGED
@@ -5,6 +5,39 @@ Unreleased section to make new releases easy.
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
- Initial release
8
+ ## [0.3.0] - 2021-06-04
9
+
10
+ ### Added
11
+
12
+ - Added support for delay exchanges to process messages after a fixed delay
13
+ - Increased documentation
14
+ - Added Warren::Message::Simple for wrapping just routing key and payload.
15
+ - Added optional worker_count to warren_consumers.yml to control number of worker threads
16
+
17
+ ### Removed
18
+
19
+ - Warren::Handler::Test and Warren::Handler::Test::Channel no loner respond to
20
+ `add_exchange`. These methods were undocumented, and unused internally.
21
+
22
+ ## Changed
23
+
24
+ - Messages must now implement `#headers`, although simply returning an empty
25
+ hash is sufficient.
26
+ See {Warren::Message::Simple#headers} for example
27
+ - Subscriber templates now use the path 'app/warren/subscriber' rather than
28
+ 'app/warren/subscribers' to correctly match class namespacing.
29
+ - 3 consumer worker threads will be spun up by default
30
+
31
+ ## [0.2.0]
32
+
33
+ ### Added
34
+
35
+ - Added railties to automatically initialize and configure Warren in rails apps.
36
+ You can remove the `config/initializers/warren.rb` and the `config.warren = config_for(:warren)`
37
+ line from `config/application.rb`
38
+ - Added `warren config` CLI to help generate a warren.yml configuration file.
39
+ - Added warren consumers managed through `warren consumer`
40
+
41
+ ## Initial release
9
42
 
10
43
  - 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', '~> 12.0'
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.1.0)
4
+ sanger_warren (0.3.0)
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.6)
14
+ activesupport (= 5.2.6)
15
+ activerecord (5.2.6)
16
+ activemodel (= 5.2.6)
17
+ activesupport (= 5.2.6)
18
+ arel (>= 9.0)
19
+ activesupport (5.2.6)
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
- ast (2.4.1)
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.2)
17
- connection_pool (2.2.3)
29
+ coderay (1.1.3)
30
+ concurrent-ruby (1.1.8)
31
+ connection_pool (2.2.5)
18
32
  diff-lcs (1.4.4)
19
- docile (1.3.2)
20
- method_source (0.9.2)
21
- multi_json (1.13.1)
22
- parallel (1.19.2)
23
- parser (2.7.2.0)
33
+ docile (1.4.0)
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.1.1)
24
41
  ast (~> 2.4.1)
25
- pry (0.12.2)
26
- coderay (~> 1.1.0)
27
- method_source (~> 0.9.0)
42
+ pry (0.14.1)
43
+ coderay (~> 1.1)
44
+ method_source (~> 1.0)
28
45
  rainbow (3.0.0)
29
- rake (12.3.3)
30
- regexp_parser (1.8.2)
31
- rexml (3.2.4)
32
- rspec (3.9.0)
33
- rspec-core (~> 3.9.0)
34
- rspec-expectations (~> 3.9.0)
35
- rspec-mocks (~> 3.9.0)
36
- rspec-core (3.9.3)
37
- rspec-support (~> 3.9.3)
38
- rspec-expectations (3.9.2)
46
+ rake (13.0.3)
47
+ regexp_parser (2.1.1)
48
+ rexml (3.2.5)
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.9.0)
41
- rspec-mocks (3.9.1)
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.9.0)
44
- rspec-support (3.9.3)
45
- rubocop (1.0.0)
60
+ rspec-support (~> 3.10.0)
61
+ rspec-support (3.10.2)
62
+ rubocop (1.15.0)
46
63
  parallel (~> 1.10)
47
- parser (>= 2.7.1.5)
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 (>= 0.6.0)
68
+ rubocop-ast (>= 1.5.0, < 2.0)
52
69
  ruby-progressbar (~> 1.7)
53
- unicode-display_width (>= 1.4.0, < 2.0)
54
- rubocop-ast (1.0.0)
55
- parser (>= 2.7.1.5)
56
- ruby-progressbar (1.10.1)
57
- simplecov (0.19.0)
70
+ unicode-display_width (>= 1.4.0, < 3.0)
71
+ rubocop-ast (1.5.0)
72
+ parser (>= 3.0.1.1)
73
+ rubocop-rake (0.5.1)
74
+ rubocop
75
+ rubocop-rspec (2.3.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
- unicode-display_width (1.7.0)
62
- yard (0.9.25)
84
+ simplecov_json_formatter (0.1.3)
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 (~> 12.0)
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.1.4
109
+ 2.2.8
data/README.md CHANGED
@@ -14,68 +14,158 @@ gem 'sanger-warren'
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle install
17
+ ```bash
18
+ bundle install
19
+ ```
18
20
 
19
21
  Or install it yourself as:
20
22
 
21
- $ gem install sanger-warren
23
+ ```bash
24
+ gem install sanger_warren
25
+ ```
22
26
 
23
27
  ## Usage
24
28
 
25
- If using with a Rails app, here's an example to get you started:
29
+ ### Basic setup
30
+
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
+ In rails 5 you will need to add the following to your `config/application.rb`
36
+ to ensure the auto-loader can find the subscribers.
26
37
 
27
38
  ```ruby
28
- # config/initializers/warren.rb
29
- require 'warren'
39
+ config.autoload_paths += %W{#{Rails.root}/app}
40
+ ```
41
+
42
+ ### Handler types
30
43
 
31
- Warren.setup(Rails.application.config.warren.deep_symbolize_keys.slice(:type, :config))
44
+ In development mode, warren is usually configured to log to the console only. If
45
+ you wish to enable broadcast mode, the easiest way is via an environmental
46
+ variable, WARREN_TYPE.
47
+
48
+ ```bash
49
+ WARREN_TYPE=broadcast bundle exec rails s
32
50
  ```
33
51
 
52
+ ### Broadcasting a message
53
+
54
+ To broadcast a message, simply push the message onto the message handler
55
+
34
56
  ```ruby
35
- # config/application.rb
36
- # ...
37
- config.warren = config_for(:warren)
38
- # ...
57
+ Warren.handler << message
39
58
  ```
40
59
 
41
- ```yaml
42
- # config/warren.yml
43
- development:
44
- type: log
45
- config: # Useful to allow easy switching to broadcast in development
46
- routing_key_prefix: 'dev'
47
- server:
48
- host: localhost
49
- port: 5672
50
- username: guest
51
- password: guest
52
- vhost: /
53
- frame_max: 0
54
- heartbeat: 30
55
- exchange: exchange_to_use
56
- test:
57
- type: test
58
- production: # In practice keep this out of your source control
59
- type: broadcast
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
60
+ Message should be an object that responds to routing_key and payload. The handler
61
+ will automatically prefix the routing key with the 'routing_key_prefix' configured
62
+ in the warren.yml file. By default this is usually the name of your environment.
63
+
64
+ If you are sending out multiple messages, you can check out a channel from the
65
+ connection pool, and use that instead.
66
+
67
+ ```ruby
68
+ Warren.handler.with_channel do |channel|
69
+ channel << message_a
70
+ channel << message_b
71
+ end
72
+ ```
73
+
74
+ ### Setting up a consumer
75
+
76
+ A command line interface exists to assist with setting up consumers. It be be
77
+ invoked with:
78
+
79
+ ```bash
80
+ bundle exec warren consumer add
71
81
  ```
72
82
 
83
+ This will guide you through configuration, and template out a subscriber class.
84
+ Subscribers receive the message payload, and metadata information and process
85
+ them in their #process method.
86
+
87
+ For more information about optional command line arguments you can supply to
88
+ the cli use:
89
+
90
+ ```bash
91
+ bundle exec warren consumer add --help
92
+ ```
93
+
94
+ #### Opinionated defaults
95
+
96
+ The cli makes some opinionated assumptions to simplify setup process:
97
+
98
+ - Consumers will use a subscriber class named Warren::Subscribed::CamelCasedConsumerName
99
+ - All consumers will dead-letter to the fanout exchange consumer-name.dead_letters
100
+ - consumer-name.dead_letters will be bound to a queue of the same name
101
+ - All queues and exchanges are durable
102
+
103
+ These options can be over-ridden in the warren_consumers.yml file if necessary.
104
+ If you wish to completely disable dead-letter queue configuration, such as when
105
+ using policies, then you can set dead_letters to false.
106
+
107
+ #### Delayed messaged
108
+
109
+ Warren uses a delay exchange / queue approach for delaying the redelivery of messages.
110
+ We don't currently support the
111
+ [delayed message exchange plugin](https://github.com/rabbitmq/rabbitmq-delayed-message-exchange)
112
+
113
+ The way this works:
114
+
115
+ - Consumers with a delay option will automatically register an exchange and a queue
116
+ - By default both of these will be named '<consumer_name>.delay' although you can
117
+ override this by updating `warren_consumers.yml`
118
+ - The '<consumer_name>.delay' queue will have a time-to-live (ttl) set, after
119
+ which any messages on the queue will be dead-lettered
120
+ - The dead-letter exchange for this queue is configured to an empty string `''`
121
+ which corresponds to the 'default exchange', and the routing key is set to
122
+ match the original queue name.
123
+ - This exchange is a little bit special, and automatically routes messages to
124
+ any queue on the host where the queue name matches the message routing key.
125
+
126
+ This approach avoids repeat delivery of the message to any other queues bound
127
+ to the original exchange, and avoids the need for further exchanges or bindings.
128
+
129
+ ### Running consumers
130
+
131
+ To run all configure consumers use:
132
+
133
+ ```bash
134
+ bundle exec warren consumer start
135
+ ```
136
+
137
+ You can also run only a subset of consumers:
138
+
139
+ ```bash
140
+ bundle exec warren consumer start --consumers=consumer_name other_consumer
141
+ ```
142
+
143
+ If you are testing in development, don't forget to set the WARREN_TYPE
144
+ environmental variable if you want to pull messages off an actual queue.
145
+
146
+ ```bash
147
+ WARREN_TYPE=broadcast bundle exec warren consumer start
148
+ ```
149
+
150
+ ## Testing
151
+
152
+ Warren provides useful helpers to assist with testing. Helper documentation, and
153
+ some testing examples can be found in the documentation for the
154
+ {Warren::Handler::Test test helper}, or online at
155
+ [rubydoc.info](https://rubydoc.info/gems/sanger_warren/Warren/Handler/Test)
156
+
73
157
  ## Development
74
158
 
75
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
159
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
160
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
161
+ prompt that will allow you to experiment.
76
162
 
77
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
163
+ To install this gem onto your local machine, run `bundle exec rake install`. To
164
+ release a new version, update the version number in `version.rb`, and then run
165
+ `bundle exec rake release`, which will create a git tag for the version, push
166
+ git commits and tags, and push the `.gem` file to
167
+ [rubygems.org](https://rubygems.org).
78
168
 
79
169
  ## Contributing
80
170
 
81
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/Warren.
171
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/sanger/warren)