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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08237db3ed2d846148e3e1b127b737d660cb48f755489ced7fbda20d582fb3c2'
4
- data.tar.gz: 41dc24f4262cc1b641e985058d7ef6b1cb294ef9e26c42775ac68bd21182c8e3
3
+ metadata.gz: f6f14e9809f8c71405a3696920321ebbf7477c7f0ecf05421a3ffd85f4fbccfc
4
+ data.tar.gz: 5e13bbba217f9b09ad08433178e03f822a6f97e207c80e532a5c8b15c8d36b7b
5
5
  SHA512:
6
- metadata.gz: e60a34f8902db181b06978f0b554485c8f69148e9111b2a325ad6b37b13dc4abef93f5e8d010ad4e2d2d7dab4dcdfddfa51f6b5fe5866e037d9d437e85095af2
7
- data.tar.gz: 98a52f7cdfaf2815f6b83a5166791bb83ab84aaa37e87ed9b4d68534fccb7a9efe14ec0c618467bd24f8c67deecd2124833245b0e3bc7b156ca48ff2a4762bb6
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
- # 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/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ Unreleased section to make new releases easy.
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
- Initial release
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', '~> 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.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
- 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)
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.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.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.12.2)
26
- coderay (~> 1.1.0)
27
- method_source (~> 0.9.0)
42
+ pry (0.14.0)
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)
46
+ rake (13.0.3)
47
+ regexp_parser (2.1.1)
31
48
  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)
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.11.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.2.0, < 2.0)
52
69
  ruby-progressbar (~> 1.7)
53
- unicode-display_width (>= 1.4.0, < 2.0)
54
- rubocop-ast (1.0.0)
70
+ unicode-display_width (>= 1.4.0, < 3.0)
71
+ rubocop-ast (1.4.1)
55
72
  parser (>= 2.7.1.5)
56
- ruby-progressbar (1.10.1)
57
- simplecov (0.19.0)
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
- unicode-display_width (1.7.0)
62
- yard (0.9.25)
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 (~> 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,129 @@ 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
26
30
 
27
- ```ruby
28
- # config/initializers/warren.rb
29
- require 'warren'
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
- Warren.setup(Rails.application.config.warren.deep_symbolize_keys.slice(:type, :config))
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
- # config/application.rb
36
- # ...
37
- config.warren = config_for(:warren)
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
- ```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
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 `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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 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).
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 at https://github.com/[USERNAME]/Warren.
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 'Warren'
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
- # require "pry"
12
- # Pry.start
13
-
14
- require 'irb'
15
- IRB.start(__FILE__)
11
+ require 'pry'
12
+ Pry.start