jackhammer 1.3.5 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 485b5598534853da9cc94ce3402e8e81e1f261820208f04d4f343783cf82e231
4
- data.tar.gz: e8ae165eb429b89065c8cb3630457bffc15d1be6a9e59826d52466f2a28b19dd
3
+ metadata.gz: 07cb37d23a78ea8dd8dbd93a5b92ef2fca79b28d7fcdf3aeb77bd28518fb76f6
4
+ data.tar.gz: 8f17dd231268a19d3dd62132af463b36ab622cfc90c31a8a3fbaed7db0473b5a
5
5
  SHA512:
6
- metadata.gz: b505c5468529bb070b6fd193a460a0252134886059b22858961f54af1932e56fb6096fe9f4fe966e32c76856cb85aad8451fa2aaf22d6c93f97f5d4722b8a92f
7
- data.tar.gz: 35afe310870caf60d6a505c9f5839f4043014f7c651166d129116dfa012da4f54f92dd8718ca7ab74f42e9c9f0442e136331134739597e5cecd155698ca126bc
6
+ metadata.gz: aead2222e48d460fd6908772fe3889a6538b1609931011233f4abe0beed49b1d7cb4f83046c5fdbf67bc0fc8cf788393f360f67e45b453bfd05e0fb807329c32
7
+ data.tar.gz: e2aa6e13ed05e8b9efe843c6a8b464d5f87470cdf7683254bbc06b552dbef0a8e2ac8c9712e199b3e0a2885ccc6089226d02ad4d83b0fcf62f061d21e9cc7104
data/.bundler-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.21
@@ -3,16 +3,14 @@ version: 1
3
3
  update_configs:
4
4
  - package_manager: "ruby:bundler"
5
5
  directory: "/"
6
- update_schedule: "monthly"
6
+ update_schedule: "daily"
7
7
  commit_message:
8
8
  prefix: "[dependabot]"
9
9
  allowed_updates:
10
10
  - match:
11
- update_type: "all"
11
+ dependency_type: "all"
12
+ update_type: "security"
12
13
  automerged_updates:
13
14
  - match:
14
- dependency_type: "development"
15
- update_type: "all"
16
- - match:
17
- dependency_type: "production"
18
- update_type: "all"
15
+ dependency_type: "all"
16
+ update_type: "security:patch"
@@ -1,7 +1,7 @@
1
- # automatically approve PRs submitted by Dependabot
1
+ # automatically approve PRs submitted by Dependabot or Renofidev
2
2
  # this will allow Dependabot to automatically merge dependency update PRs where CI passes
3
3
  # from: https://github.com/hmarr/auto-approve-action
4
- name: Auto approve Dependabot PRs
4
+ name: Auto approve dependency upgrades PRs
5
5
 
6
6
  on:
7
7
  pull_request
@@ -11,6 +11,6 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
13
  - uses: hmarr/auto-approve-action@v2.0.0
14
- if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
14
+ if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]' || github.actor == 'renofidev'
15
15
  with:
16
16
  github-token: "${{ secrets.GITHUB_TOKEN }}"
@@ -0,0 +1,19 @@
1
+ name: automerge
2
+ on:
3
+ pull_request_review:
4
+ types:
5
+ - submitted
6
+ check_suite:
7
+ types:
8
+ - completed
9
+ status: {}
10
+ jobs:
11
+ automerge:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: automerge
15
+ uses: "pascalgn/automerge-action@v0.12.0"
16
+ env:
17
+ GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
18
+ MERGE_METHOD: squash
19
+ MERGE_DELETE_BRANCH: true
data/.travis.yml CHANGED
@@ -5,6 +5,7 @@ cache: bundler
5
5
  rvm:
6
6
  - 2.6
7
7
  - 2.7
8
+ - 3.0
8
9
  before_install: gem install bundler
9
10
  script:
10
11
  - bundle exec rake spec
data/Gemfile.lock CHANGED
@@ -1,79 +1,86 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jackhammer (1.3.5)
5
- bunny (~> 2.14)
4
+ jackhammer (1.5.0)
5
+ bunny (~> 2.17)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (6.0.3.2)
11
- activesupport (= 6.0.3.2)
12
- activerecord (6.0.3.2)
13
- activemodel (= 6.0.3.2)
14
- activesupport (= 6.0.3.2)
15
- activesupport (6.0.3.2)
10
+ activemodel (6.1.4)
11
+ activesupport (= 6.1.4)
12
+ activerecord (6.1.4)
13
+ activemodel (= 6.1.4)
14
+ activesupport (= 6.1.4)
15
+ activesupport (6.1.4)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
- i18n (>= 0.7, < 2)
18
- minitest (~> 5.1)
19
- tzinfo (~> 1.1)
20
- zeitwerk (~> 2.2, >= 2.2.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ zeitwerk (~> 2.3)
21
21
  amq-protocol (2.3.2)
22
- ast (2.4.1)
23
- bunny (2.15.0)
22
+ ast (2.4.2)
23
+ bunny (2.19.0)
24
24
  amq-protocol (~> 2.3, >= 2.3.1)
25
+ sorted_set (~> 1, >= 1.0.2)
25
26
  bunny-mock (1.7.0)
26
27
  bunny (>= 1.7)
27
28
  byebug (11.1.3)
28
- concurrent-ruby (1.1.6)
29
+ concurrent-ruby (1.1.9)
29
30
  diff-lcs (1.4.4)
30
- i18n (1.8.3)
31
+ i18n (1.8.10)
31
32
  concurrent-ruby (~> 1.0)
32
- minitest (5.14.1)
33
- parallel (1.19.2)
34
- parser (2.7.1.4)
33
+ minitest (5.14.4)
34
+ parallel (1.20.1)
35
+ parser (3.0.1.1)
35
36
  ast (~> 2.4.1)
36
37
  rainbow (3.0.0)
37
- rake (13.0.1)
38
- regexp_parser (1.7.1)
39
- rexml (3.2.4)
40
- rspec (3.9.0)
41
- rspec-core (~> 3.9.0)
42
- rspec-expectations (~> 3.9.0)
43
- rspec-mocks (~> 3.9.0)
44
- rspec-core (3.9.2)
45
- rspec-support (~> 3.9.3)
46
- rspec-expectations (3.9.2)
38
+ rake (13.0.4)
39
+ rbtree (0.4.4)
40
+ regexp_parser (2.1.1)
41
+ rexml (3.2.5)
42
+ rspec (3.10.0)
43
+ rspec-core (~> 3.10.0)
44
+ rspec-expectations (~> 3.10.0)
45
+ rspec-mocks (~> 3.10.0)
46
+ rspec-core (3.10.1)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-expectations (3.10.1)
47
49
  diff-lcs (>= 1.2.0, < 2.0)
48
- rspec-support (~> 3.9.0)
49
- rspec-mocks (3.9.1)
50
+ rspec-support (~> 3.10.0)
51
+ rspec-mocks (3.10.2)
50
52
  diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.9.0)
52
- rspec-support (3.9.3)
53
- rubocop (0.88.0)
53
+ rspec-support (~> 3.10.0)
54
+ rspec-support (3.10.2)
55
+ rubocop (1.18.3)
54
56
  parallel (~> 1.10)
55
- parser (>= 2.7.1.1)
57
+ parser (>= 3.0.0.0)
56
58
  rainbow (>= 2.2.2, < 4.0)
57
- regexp_parser (>= 1.7)
59
+ regexp_parser (>= 1.8, < 3.0)
58
60
  rexml
59
- rubocop-ast (>= 0.1.0, < 1.0)
61
+ rubocop-ast (>= 1.7.0, < 2.0)
60
62
  ruby-progressbar (~> 1.7)
61
- unicode-display_width (>= 1.4.0, < 2.0)
62
- rubocop-ast (0.1.0)
63
- parser (>= 2.7.0.1)
64
- rubocop-performance (1.7.0)
65
- rubocop (>= 0.82.0)
66
- rubocop-rspec (1.42.0)
67
- rubocop (>= 0.87.0)
68
- ruby-progressbar (1.10.1)
69
- thread_safe (0.3.6)
70
- tzinfo (1.2.7)
71
- thread_safe (~> 0.1)
72
- unicode-display_width (1.7.0)
73
- zeitwerk (2.3.1)
63
+ unicode-display_width (>= 1.4.0, < 3.0)
64
+ rubocop-ast (1.7.0)
65
+ parser (>= 3.0.1.1)
66
+ rubocop-rake (0.6.0)
67
+ rubocop (~> 1.0)
68
+ rubocop-rspec (2.4.0)
69
+ rubocop (~> 1.0)
70
+ rubocop-ast (>= 1.1.0)
71
+ ruby-progressbar (1.11.0)
72
+ set (1.0.1)
73
+ sorted_set (1.0.3)
74
+ rbtree
75
+ set (~> 1.0)
76
+ tzinfo (2.0.4)
77
+ concurrent-ruby (~> 1.0)
78
+ unicode-display_width (2.0.0)
79
+ zeitwerk (2.4.2)
74
80
 
75
81
  PLATFORMS
76
82
  ruby
83
+ x86_64-linux
77
84
 
78
85
  DEPENDENCIES
79
86
  activerecord
@@ -84,8 +91,8 @@ DEPENDENCIES
84
91
  rake
85
92
  rspec
86
93
  rubocop
87
- rubocop-performance
94
+ rubocop-rake
88
95
  rubocop-rspec
89
96
 
90
97
  BUNDLED WITH
91
- 2.1.4
98
+ 2.2.15
data/README.md CHANGED
@@ -90,6 +90,8 @@ module MyApp
90
90
  config.publish_options = { mandatory: true, persistent: true }
91
91
  config.yaml_config = "config/jackhammer.yml"
92
92
  config.app_name = "my_app"
93
+ config.client_middleware.use MyClientMiddleware, some_arg: 1, other_arg: 2
94
+ config.server_middleware.use MyServerMiddleware
93
95
  end
94
96
  end
95
97
  end
@@ -162,10 +164,47 @@ The intent of the options might not be obvious by looking at the name.
162
164
  overridden by passing the same options as arguments in your code).
163
165
  - **yaml_config** defines the file location of the Topic Exchange YAML
164
166
  configuration file.
167
+ - **client_middleware** defines hooks that will be executed prior to publishing a message to a topic
168
+ - **server_middleware** defines hooks that will be executed prior to running the message handler
165
169
 
166
170
  You can find defaults specified in the Jackhammer::Configuration class
167
171
  constructor.
168
172
 
173
+ ### Middleware
174
+
175
+ Middleware allows you to hook into message publishing (client) and handling (server).
176
+
177
+ It can be used to transform the passed in arguments before passing them along or to halt the execution completely.
178
+ The execution will be halted if the middleware instance does not yield.
179
+
180
+ #### Example client middleware
181
+
182
+ ```ruby
183
+ class MyClientMiddleware
184
+ def initialize(name)
185
+ @name = name
186
+ end
187
+
188
+ def call(message, options)
189
+ options[:headers][:hello] = @name
190
+
191
+ yield message, options
192
+ end
193
+ end
194
+ ```
195
+
196
+ #### Example server middleware
197
+
198
+ ```ruby
199
+ class MyServerMiddleware
200
+ def call(handler:, delivery_info:, properties:, content:)
201
+ puts "Hello, #{properties[:headers]['name']}!"
202
+
203
+ yield handler: handler, delivery_info: delivery_info, properties: properties, content: content
204
+ end
205
+ end
206
+ ```
207
+
169
208
  ## Development
170
209
 
171
210
  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.
data/jackhammer.gemspec CHANGED
@@ -22,7 +22,9 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'bunny', '~> 2.14'
25
+ spec.required_ruby_version = '>= 2.6'
26
+
27
+ spec.add_dependency 'bunny', '~> 2.17'
26
28
 
27
29
  spec.add_development_dependency 'activerecord'
28
30
  spec.add_development_dependency 'bundler'
@@ -31,6 +33,6 @@ Gem::Specification.new do |spec|
31
33
  spec.add_development_dependency 'rake'
32
34
  spec.add_development_dependency 'rspec'
33
35
  spec.add_development_dependency 'rubocop'
34
- spec.add_development_dependency 'rubocop-performance'
36
+ spec.add_development_dependency 'rubocop-rake'
35
37
  spec.add_development_dependency 'rubocop-rspec'
36
38
  end
data/lib/jackhammer.rb CHANGED
@@ -7,6 +7,7 @@ require 'jackhammer/exceptions'
7
7
  require 'jackhammer/log'
8
8
  require 'jackhammer/configuration'
9
9
  require 'jackhammer/message_receiver'
10
+ require 'jackhammer/middleware_collection'
10
11
  require 'jackhammer/queue_name'
11
12
  require 'jackhammer/queue'
12
13
  require 'jackhammer/topic'
@@ -46,5 +47,13 @@ module Jackhammer
46
47
  opts[:headers][:time] ||= time.iso8601
47
48
  end
48
49
  end
50
+
51
+ def client_middleware
52
+ configuration.client_middleware
53
+ end
54
+
55
+ def server_middleware
56
+ configuration.server_middleware
57
+ end
49
58
  end
50
59
  end
@@ -5,7 +5,7 @@ module Jackhammer
5
5
  attr_reader :logger, :opts
6
6
 
7
7
  def initialize(options = {})
8
- @logger = Logger.new STDERR
8
+ @logger = Logger.new $stderr
9
9
  @opts = { require: './config/environment' }.merge(options)
10
10
  end
11
11
 
@@ -2,6 +2,7 @@ module Jackhammer
2
2
  class Configuration
3
3
  attr_accessor(
4
4
  :app_name,
5
+ :client_middleware,
5
6
  :connection_options,
6
7
  :connection_url,
7
8
  :environment,
@@ -9,6 +10,7 @@ module Jackhammer
9
10
  :logger,
10
11
  :publish_options,
11
12
  :server,
13
+ :server_middleware,
12
14
  :yaml_config
13
15
  )
14
16
 
@@ -20,6 +22,8 @@ module Jackhammer
20
22
  @logger = Logger.new IO::NULL
21
23
  @publish_options = { mandatory: true, persistent: true }
22
24
  @yaml_config = './config/jackhammer.yml'
25
+ @client_middleware = MiddlewareCollection.new
26
+ @server_middleware = MiddlewareCollection.new
23
27
  end
24
28
 
25
29
  def self.instance
@@ -0,0 +1,29 @@
1
+ module Jackhammer
2
+ class MiddlewareCollection
3
+ def initialize
4
+ @entries = []
5
+ end
6
+
7
+ def use(klass, *args, **kwargs, &block)
8
+ @entries << Entry.new(klass: klass, args: args, kwargs: kwargs, block: block)
9
+ end
10
+
11
+ def call(*args, **kwargs, &block)
12
+ call_chain = @entries.map(&:instantiate) + [block]
13
+
14
+ traverse = proc do |*procargs, **prockwargs|
15
+ call_chain.shift.call(*procargs, **prockwargs, &traverse) unless call_chain.empty?
16
+ end
17
+
18
+ traverse.call(*args, **kwargs)
19
+ end
20
+
21
+ Entry = Struct.new(:klass, :args, :kwargs, :block, keyword_init: true) do
22
+ def instantiate
23
+ return klass unless klass.respond_to?(:new)
24
+
25
+ klass.new(*args, **kwargs, &block)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -13,7 +13,15 @@ module Jackhammer
13
13
  queue.subscribe do |delivery_info, properties, content|
14
14
  Log.info { [delivery_info.inspect, properties.inspect].join(' || ') }
15
15
  Log.debug { content }
16
- handler_object.call content
16
+
17
+ Jackhammer.server_middleware.call(
18
+ handler: handler_object,
19
+ delivery_info: delivery_info,
20
+ properties: properties,
21
+ content: content
22
+ ) do |**args|
23
+ args.fetch(:handler).call args.fetch(:content)
24
+ end
17
25
  rescue StandardError => e
18
26
  Log.error e
19
27
  Jackhammer.configuration.exception_adapter.call e
@@ -22,6 +22,7 @@ module Jackhammer
22
22
  attr_accessor :env
23
23
 
24
24
  def initialize
25
+ super
25
26
  @name = :jackhammer
26
27
  @env = 'production'
27
28
  @path = './config/jackhammer.yml'
@@ -39,7 +40,7 @@ module Jackhammer
39
40
  desc @description
40
41
  task @name => Array(deps) do
41
42
  validator = ConfigurationValidator.new
42
- validator.config_yaml = YAML.safe_load(File.read(@path))
43
+ validator.config_yaml = YAML.safe_load(File.read(@path), [], [], true)
43
44
  validator.environment = env
44
45
  validator.validate
45
46
  print_results validator.errors
@@ -3,8 +3,8 @@ module Jackhammer
3
3
  QUEUE_NAME_KEY = 'queue_name'.freeze
4
4
  ROUTING_KEY_KEY = 'routing_key'.freeze
5
5
 
6
- def initialize(name:, options:, queue_config:)
7
- @topic = Jackhammer.channel.topic name, options
6
+ def initialize(name:, queue_config:, options: {})
7
+ @topic = Jackhammer.channel.topic(name, options)
8
8
  @queue_config = normalize_queue_config(queue_config)
9
9
  end
10
10
 
@@ -15,7 +15,9 @@ module Jackhammer
15
15
  # We're expecting the client to specify at least the routing_key in options
16
16
  # for each message published.
17
17
  def publish(message, options)
18
- topic.publish message, Jackhammer.publish_options(options)
18
+ Jackhammer.client_middleware.call(message, Jackhammer.publish_options(options)) do |msg, opts|
19
+ topic.publish msg, opts
20
+ end
19
21
  end
20
22
 
21
23
  def queues
@@ -1,3 +1,3 @@
1
1
  module Jackhammer
2
- VERSION = '1.3.5'.freeze
2
+ VERSION = '1.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackhammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Serok
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
11
+ date: 2021-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.14'
19
+ version: '2.17'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.14'
26
+ version: '2.17'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rubocop-performance
126
+ name: rubocop-rake
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -150,7 +150,7 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- description:
153
+ description:
154
154
  email:
155
155
  - scott@renofi.com
156
156
  executables:
@@ -158,12 +158,14 @@ executables:
158
158
  extensions: []
159
159
  extra_rdoc_files: []
160
160
  files:
161
+ - ".bundler-version"
161
162
  - ".dependabot/config.yml"
162
163
  - ".github/ISSUE_TEMPLATE/bug_report.md"
163
164
  - ".github/ISSUE_TEMPLATE/config.yml"
164
165
  - ".github/ISSUE_TEMPLATE/story.md"
165
166
  - ".github/PULL_REQUEST_TEMPLATE.md"
166
167
  - ".github/workflows/auto-approve.yml"
168
+ - ".github/workflows/auto-merge.yml"
167
169
  - ".gitignore"
168
170
  - ".rspec"
169
171
  - ".travis.yml"
@@ -181,6 +183,7 @@ files:
181
183
  - lib/jackhammer/exceptions.rb
182
184
  - lib/jackhammer/log.rb
183
185
  - lib/jackhammer/message_receiver.rb
186
+ - lib/jackhammer/middleware_collection.rb
184
187
  - lib/jackhammer/queue.rb
185
188
  - lib/jackhammer/queue_name.rb
186
189
  - lib/jackhammer/rake_task.rb
@@ -194,7 +197,7 @@ licenses:
194
197
  metadata:
195
198
  homepage_uri: https://github.com/renofi/jackhammer
196
199
  source_code_uri: https://github.com/renofi/jackhammer
197
- post_install_message:
200
+ post_install_message:
198
201
  rdoc_options: []
199
202
  require_paths:
200
203
  - lib
@@ -202,15 +205,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
205
  requirements:
203
206
  - - ">="
204
207
  - !ruby/object:Gem::Version
205
- version: '0'
208
+ version: '2.6'
206
209
  required_rubygems_version: !ruby/object:Gem::Requirement
207
210
  requirements:
208
211
  - - ">="
209
212
  - !ruby/object:Gem::Version
210
213
  version: '0'
211
214
  requirements: []
212
- rubygems_version: 3.1.2
213
- signing_key:
215
+ rubygems_version: 3.2.15
216
+ signing_key:
214
217
  specification_version: 4
215
218
  summary: Jackhammer is an opinionated facade over RabbitMQ Bunny
216
219
  test_files: []