jackhammer 1.3.3 → 1.4.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.
- checksums.yaml +4 -4
- data/.dependabot/config.yml +0 -7
- data/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
- data/.github/ISSUE_TEMPLATE/config.yml +1 -0
- data/.github/ISSUE_TEMPLATE/story.md +22 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +18 -0
- data/.github/workflows/auto-approve.yml +16 -0
- data/.github/workflows/auto-merge.yml +29 -0
- data/Gemfile.lock +46 -22
- data/README.md +39 -0
- data/Rakefile +1 -1
- data/jackhammer.gemspec +3 -0
- data/lib/jackhammer.rb +9 -0
- data/lib/jackhammer/cli.rb +1 -1
- data/lib/jackhammer/configuration.rb +4 -0
- data/lib/jackhammer/configuration_validator.rb +60 -0
- data/lib/jackhammer/message_receiver.rb +2 -0
- data/lib/jackhammer/middleware_collection.rb +29 -0
- data/lib/jackhammer/queue.rb +9 -1
- data/lib/jackhammer/queue_name.rb +1 -1
- data/lib/jackhammer/rake_task.rb +71 -0
- data/lib/jackhammer/topic.rb +3 -1
- data/lib/jackhammer/version.rb +1 -1
- metadata +27 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4aa6bdf41e8005dbbfbcdc2bacfc4fae0a8e182cb35b62fea8d961ba350ef600
|
|
4
|
+
data.tar.gz: 7ce9c945039c1e09b4cec7406c6c1e767f5bc91baf76ace5a9dcdca940f7991b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e6ace137b8bac8709c3c38cf7fe0109cda7a13e4fe59d4900bb059f9b1403c445eb67419375a9d1c7c438c84d8d55949bb59291f53aa9982f9658364f43a6283
|
|
7
|
+
data.tar.gz: b2d6807b73211b09db3db88bc02de9d2d0509a4451c4b1fc252d92e98eb5b864038c25f3482169fe0325d58b820a5a659c16efea077bf32c668a9fafd2f90ec5
|
data/.dependabot/config.yml
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Create a report to track an issue that has been identified
|
|
4
|
+
title: ''
|
|
5
|
+
labels: ''
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Describe the bug**
|
|
11
|
+
A clear and concise description of what the bug is.
|
|
12
|
+
|
|
13
|
+
**To Reproduce**
|
|
14
|
+
Steps to reproduce the behavior:
|
|
15
|
+
1. Go to '...'
|
|
16
|
+
2. Click on '....'
|
|
17
|
+
3. Scroll down to '....'
|
|
18
|
+
4. See error
|
|
19
|
+
|
|
20
|
+
**Expected behavior**
|
|
21
|
+
A clear and concise description of what you expected to happen.
|
|
22
|
+
|
|
23
|
+
**Mutation/Query**
|
|
24
|
+
|
|
25
|
+
**URL and HTTP method (for non-GQL):**
|
|
26
|
+
|
|
27
|
+
**Sentry or Logs URL:**
|
|
28
|
+
|
|
29
|
+
**User/authentication details**
|
|
30
|
+
Impacted user name or service account
|
|
31
|
+
|
|
32
|
+
**Additional context**
|
|
33
|
+
Add any other context about the problem here.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
blank_issues_enabled: false
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: New story
|
|
3
|
+
about: Add a new story for implementation
|
|
4
|
+
title: ''
|
|
5
|
+
labels: ''
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Describe the solution**
|
|
11
|
+
A clear and concise description of what you want to happen.
|
|
12
|
+
When will this feature be done?
|
|
13
|
+
|
|
14
|
+
**Describe the users**
|
|
15
|
+
Who are we building this feature for?
|
|
16
|
+
|
|
17
|
+
**Additional context**
|
|
18
|
+
Add any other context or screenshots about the feature request here.
|
|
19
|
+
Link to any applicable documents describing the feature.
|
|
20
|
+
|
|
21
|
+
**Designs**
|
|
22
|
+
Link to any applicable designs on Invision.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
## Description
|
|
2
|
+
<!--- Describe your changes in detail -->
|
|
3
|
+
|
|
4
|
+
## Related issue(s)
|
|
5
|
+
<!--- GH issue number -->
|
|
6
|
+
|
|
7
|
+
## Motivation and Context
|
|
8
|
+
<!--- Why is this change required? What problem does it solve? -->
|
|
9
|
+
<!--- If it fixes an open issue, please link to the issue here. -->
|
|
10
|
+
|
|
11
|
+
## How Has This Been Tested?
|
|
12
|
+
<!--- Please describe in detail how you tested your changes. -->
|
|
13
|
+
|
|
14
|
+
## Screenshots (if appropriate):
|
|
15
|
+
<!--- Please add any screenshots of the feature. -->
|
|
16
|
+
|
|
17
|
+
## Related PRs
|
|
18
|
+
<!--- Please add links to any related PRs (backend, component packages, etc). -->
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# automatically approve PRs submitted by Dependabot or Renofidev
|
|
2
|
+
# this will allow Dependabot to automatically merge dependency update PRs where CI passes
|
|
3
|
+
# from: https://github.com/hmarr/auto-approve-action
|
|
4
|
+
name: Auto approve dependency upgrades PRs
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
pull_request
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
auto-approve:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: hmarr/auto-approve-action@v2.0.0
|
|
14
|
+
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]' || github.actor == 'renofidev'
|
|
15
|
+
with:
|
|
16
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: automerge
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
types:
|
|
5
|
+
- labeled
|
|
6
|
+
- unlabeled
|
|
7
|
+
- synchronize
|
|
8
|
+
- opened
|
|
9
|
+
- edited
|
|
10
|
+
- ready_for_review
|
|
11
|
+
- reopened
|
|
12
|
+
- unlocked
|
|
13
|
+
pull_request_review:
|
|
14
|
+
types:
|
|
15
|
+
- submitted
|
|
16
|
+
check_suite:
|
|
17
|
+
types:
|
|
18
|
+
- completed
|
|
19
|
+
status: {}
|
|
20
|
+
jobs:
|
|
21
|
+
automerge:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- name: automerge
|
|
25
|
+
uses: "pascalgn/automerge-action@v0.11.0"
|
|
26
|
+
env:
|
|
27
|
+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
|
28
|
+
MERGE_METHOD: squash
|
|
29
|
+
MERGE_DELETE_BRANCH: true
|
data/Gemfile.lock
CHANGED
|
@@ -1,59 +1,83 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
jackhammer (1.
|
|
4
|
+
jackhammer (1.4.0)
|
|
5
5
|
bunny (~> 2.14)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
activemodel (6.0.3.4)
|
|
11
|
+
activesupport (= 6.0.3.4)
|
|
12
|
+
activerecord (6.0.3.4)
|
|
13
|
+
activemodel (= 6.0.3.4)
|
|
14
|
+
activesupport (= 6.0.3.4)
|
|
15
|
+
activesupport (6.0.3.4)
|
|
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)
|
|
21
|
+
amq-protocol (2.3.2)
|
|
22
|
+
ast (2.4.1)
|
|
23
|
+
bunny (2.17.0)
|
|
24
|
+
amq-protocol (~> 2.3, >= 2.3.1)
|
|
14
25
|
bunny-mock (1.7.0)
|
|
15
26
|
bunny (>= 1.7)
|
|
16
|
-
byebug (11.1.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
byebug (11.1.3)
|
|
28
|
+
concurrent-ruby (1.1.7)
|
|
29
|
+
diff-lcs (1.4.4)
|
|
30
|
+
i18n (1.8.5)
|
|
31
|
+
concurrent-ruby (~> 1.0)
|
|
32
|
+
minitest (5.14.2)
|
|
33
|
+
parallel (1.19.2)
|
|
34
|
+
parser (2.7.2.0)
|
|
35
|
+
ast (~> 2.4.1)
|
|
22
36
|
rainbow (3.0.0)
|
|
23
37
|
rake (13.0.1)
|
|
38
|
+
regexp_parser (1.8.2)
|
|
24
39
|
rexml (3.2.4)
|
|
25
40
|
rspec (3.9.0)
|
|
26
41
|
rspec-core (~> 3.9.0)
|
|
27
42
|
rspec-expectations (~> 3.9.0)
|
|
28
43
|
rspec-mocks (~> 3.9.0)
|
|
29
|
-
rspec-core (3.9.
|
|
30
|
-
rspec-support (~> 3.9.
|
|
31
|
-
rspec-expectations (3.9.
|
|
44
|
+
rspec-core (3.9.3)
|
|
45
|
+
rspec-support (~> 3.9.3)
|
|
46
|
+
rspec-expectations (3.9.2)
|
|
32
47
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
33
48
|
rspec-support (~> 3.9.0)
|
|
34
49
|
rspec-mocks (3.9.1)
|
|
35
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
36
51
|
rspec-support (~> 3.9.0)
|
|
37
|
-
rspec-support (3.9.
|
|
38
|
-
rubocop (0.
|
|
39
|
-
jaro_winkler (~> 1.5.1)
|
|
52
|
+
rspec-support (3.9.3)
|
|
53
|
+
rubocop (0.93.1)
|
|
40
54
|
parallel (~> 1.10)
|
|
41
|
-
parser (>= 2.7.
|
|
55
|
+
parser (>= 2.7.1.5)
|
|
42
56
|
rainbow (>= 2.2.2, < 4.0)
|
|
57
|
+
regexp_parser (>= 1.8)
|
|
43
58
|
rexml
|
|
59
|
+
rubocop-ast (>= 0.6.0)
|
|
44
60
|
ruby-progressbar (~> 1.7)
|
|
45
61
|
unicode-display_width (>= 1.4.0, < 2.0)
|
|
46
|
-
rubocop-
|
|
47
|
-
|
|
48
|
-
rubocop-
|
|
49
|
-
rubocop (>= 0.
|
|
62
|
+
rubocop-ast (0.7.1)
|
|
63
|
+
parser (>= 2.7.1.5)
|
|
64
|
+
rubocop-performance (1.8.1)
|
|
65
|
+
rubocop (>= 0.87.0)
|
|
66
|
+
rubocop-ast (>= 0.4.0)
|
|
67
|
+
rubocop-rspec (1.43.2)
|
|
68
|
+
rubocop (~> 0.87)
|
|
50
69
|
ruby-progressbar (1.10.1)
|
|
70
|
+
thread_safe (0.3.6)
|
|
71
|
+
tzinfo (1.2.7)
|
|
72
|
+
thread_safe (~> 0.1)
|
|
51
73
|
unicode-display_width (1.7.0)
|
|
74
|
+
zeitwerk (2.4.0)
|
|
52
75
|
|
|
53
76
|
PLATFORMS
|
|
54
77
|
ruby
|
|
55
78
|
|
|
56
79
|
DEPENDENCIES
|
|
80
|
+
activerecord
|
|
57
81
|
bundler
|
|
58
82
|
bunny-mock
|
|
59
83
|
byebug
|
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/Rakefile
CHANGED
data/jackhammer.gemspec
CHANGED
|
@@ -22,8 +22,11 @@ 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.required_ruby_version = '>= 2.6'
|
|
26
|
+
|
|
25
27
|
spec.add_dependency 'bunny', '~> 2.14'
|
|
26
28
|
|
|
29
|
+
spec.add_development_dependency 'activerecord'
|
|
27
30
|
spec.add_development_dependency 'bundler'
|
|
28
31
|
spec.add_development_dependency 'bunny-mock'
|
|
29
32
|
spec.add_development_dependency 'byebug'
|
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
|
data/lib/jackhammer/cli.rb
CHANGED
|
@@ -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,60 @@
|
|
|
1
|
+
module Jackhammer
|
|
2
|
+
class ConfigurationValidator
|
|
3
|
+
attr_accessor :config_yaml, :environment, :errors
|
|
4
|
+
|
|
5
|
+
def initialize
|
|
6
|
+
@errors = []
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def validate
|
|
10
|
+
validate_environment_defined
|
|
11
|
+
return if errors.any?
|
|
12
|
+
validate_topic_exchange_defined
|
|
13
|
+
return if errors.any?
|
|
14
|
+
validate_queues_defined
|
|
15
|
+
return if errors.any?
|
|
16
|
+
validate_handlers_defined
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def validate_environment_defined
|
|
20
|
+
return if config_yaml[environment]
|
|
21
|
+
|
|
22
|
+
add_error("Environment '#{environment}' is not defined")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def validate_topic_exchange_defined
|
|
26
|
+
return if config_yaml[environment].keys.any?
|
|
27
|
+
|
|
28
|
+
add_error("Environment '#{environment}' does not define a topic exchange")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def validate_queues_defined
|
|
32
|
+
topics = config_yaml[environment].keys
|
|
33
|
+
topics.each do |topic|
|
|
34
|
+
begin
|
|
35
|
+
next if config_yaml[environment][topic]['queues']
|
|
36
|
+
rescue StandardError
|
|
37
|
+
false
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
add_error("Topic '#{topic}' does not define any queues")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def validate_handlers_defined
|
|
45
|
+
config_yaml[environment].each do |exchange_name, exchange_config|
|
|
46
|
+
exchange_config['queues'].each do |qconfig|
|
|
47
|
+
Object.const_get(qconfig['handler'])
|
|
48
|
+
rescue NameError
|
|
49
|
+
add_error("Uninitialized constant #{qconfig['handler']}")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def add_error(str)
|
|
57
|
+
@errors << str
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Jackhammer
|
|
2
|
+
class MiddlewareCollection
|
|
3
|
+
def initialize
|
|
4
|
+
@entries = []
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def use(klass, *args, &block)
|
|
8
|
+
@entries << Entry.new(klass: klass, args: args, block: block)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def call(*args, &block)
|
|
12
|
+
call_chain = @entries.map(&:instantiate) + [block]
|
|
13
|
+
|
|
14
|
+
traverse = proc do |*arguments|
|
|
15
|
+
call_chain.shift.call(*arguments, &traverse) unless call_chain.empty?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
traverse.call(*args)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Entry = Struct.new(:klass, :args, :block, keyword_init: true) do
|
|
22
|
+
def instantiate
|
|
23
|
+
return klass unless klass.respond_to?(:new)
|
|
24
|
+
|
|
25
|
+
klass.new(*args, &block)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/jackhammer/queue.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
|
@@ -7,7 +7,7 @@ module Jackhammer
|
|
|
7
7
|
def self.from_routing_key(routing_key)
|
|
8
8
|
fail(InvalidConfigError, "app_name must be set to determine queue_name from routing_key") if app_name.to_s.empty?
|
|
9
9
|
|
|
10
|
-
"#{app_name}_#{routing_key}_q".gsub(/[^\w]+/, '_').
|
|
10
|
+
"#{app_name}_#{routing_key}_q".gsub(/[^\w]+/, '_').squeeze('_')
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/tasklib'
|
|
3
|
+
require 'yaml'
|
|
4
|
+
require 'jackhammer/configuration_validator'
|
|
5
|
+
|
|
6
|
+
module Jackhammer
|
|
7
|
+
class RakeTask < ::Rake::TaskLib
|
|
8
|
+
# Name of test task. (default is :jackhammer)
|
|
9
|
+
attr_accessor :name
|
|
10
|
+
|
|
11
|
+
# File path of the configuration file. (default is ./config/jackhammer.yml)
|
|
12
|
+
attr_accessor :path
|
|
13
|
+
|
|
14
|
+
# Description of the test task. (default is 'Validate Jackhammer
|
|
15
|
+
# configuration')
|
|
16
|
+
attr_accessor :description
|
|
17
|
+
|
|
18
|
+
# Task prerequisites.
|
|
19
|
+
attr_accessor :deps
|
|
20
|
+
|
|
21
|
+
# Specifies the environment to inspect. (default is 'production')
|
|
22
|
+
attr_accessor :env
|
|
23
|
+
|
|
24
|
+
def initialize
|
|
25
|
+
super
|
|
26
|
+
@name = :jackhammer
|
|
27
|
+
@env = 'production'
|
|
28
|
+
@path = './config/jackhammer.yml'
|
|
29
|
+
@description = 'Validate Jackhammer configuration'
|
|
30
|
+
@deps = []
|
|
31
|
+
yield self if block_given?
|
|
32
|
+
if @name.is_a?(Hash)
|
|
33
|
+
@deps = @name.values.first
|
|
34
|
+
@name = @name.keys.first
|
|
35
|
+
end
|
|
36
|
+
define
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def define
|
|
40
|
+
desc @description
|
|
41
|
+
task @name => Array(deps) do
|
|
42
|
+
validator = ConfigurationValidator.new
|
|
43
|
+
validator.config_yaml = YAML.safe_load(File.read(@path), [], [], true)
|
|
44
|
+
validator.environment = env
|
|
45
|
+
validator.validate
|
|
46
|
+
print_results validator.errors
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def print_results(errors)
|
|
53
|
+
puts "Jackhammer configuration #{path}\n"
|
|
54
|
+
if errors.any?
|
|
55
|
+
puts red("Problems identified: #{errors.size}\n")
|
|
56
|
+
errors.each { |error| puts red(error) }
|
|
57
|
+
exit 1
|
|
58
|
+
else
|
|
59
|
+
puts green('OK')
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def red(text)
|
|
64
|
+
"\e[1;31m#{text}\e[0m"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def green(text)
|
|
68
|
+
"\e[1;32m#{text}\e[0m"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
data/lib/jackhammer/topic.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/jackhammer/version.rb
CHANGED
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.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Scott Serok
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-10-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bunny
|
|
@@ -24,6 +24,20 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '2.14'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activerecord
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: bundler
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -145,6 +159,12 @@ extensions: []
|
|
|
145
159
|
extra_rdoc_files: []
|
|
146
160
|
files:
|
|
147
161
|
- ".dependabot/config.yml"
|
|
162
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
|
163
|
+
- ".github/ISSUE_TEMPLATE/config.yml"
|
|
164
|
+
- ".github/ISSUE_TEMPLATE/story.md"
|
|
165
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
|
166
|
+
- ".github/workflows/auto-approve.yml"
|
|
167
|
+
- ".github/workflows/auto-merge.yml"
|
|
148
168
|
- ".gitignore"
|
|
149
169
|
- ".rspec"
|
|
150
170
|
- ".travis.yml"
|
|
@@ -158,11 +178,14 @@ files:
|
|
|
158
178
|
- lib/jackhammer.rb
|
|
159
179
|
- lib/jackhammer/cli.rb
|
|
160
180
|
- lib/jackhammer/configuration.rb
|
|
181
|
+
- lib/jackhammer/configuration_validator.rb
|
|
161
182
|
- lib/jackhammer/exceptions.rb
|
|
162
183
|
- lib/jackhammer/log.rb
|
|
163
184
|
- lib/jackhammer/message_receiver.rb
|
|
185
|
+
- lib/jackhammer/middleware_collection.rb
|
|
164
186
|
- lib/jackhammer/queue.rb
|
|
165
187
|
- lib/jackhammer/queue_name.rb
|
|
188
|
+
- lib/jackhammer/rake_task.rb
|
|
166
189
|
- lib/jackhammer/server.rb
|
|
167
190
|
- lib/jackhammer/topic.rb
|
|
168
191
|
- lib/jackhammer/topic_manager.rb
|
|
@@ -181,14 +204,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
181
204
|
requirements:
|
|
182
205
|
- - ">="
|
|
183
206
|
- !ruby/object:Gem::Version
|
|
184
|
-
version: '
|
|
207
|
+
version: '2.6'
|
|
185
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
209
|
requirements:
|
|
187
210
|
- - ">="
|
|
188
211
|
- !ruby/object:Gem::Version
|
|
189
212
|
version: '0'
|
|
190
213
|
requirements: []
|
|
191
|
-
rubygems_version: 3.1.
|
|
214
|
+
rubygems_version: 3.1.4
|
|
192
215
|
signing_key:
|
|
193
216
|
specification_version: 4
|
|
194
217
|
summary: Jackhammer is an opinionated facade over RabbitMQ Bunny
|