jackhammer 1.3.4 → 1.3.5

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: 38bd9a7e8b2be82da0c8751c93a24c77b40a580de54b40041479e7585487d160
4
- data.tar.gz: 06b2c035650f92b9bf48297107457d99820bd54bb80f97a63463b462cc52e320
3
+ metadata.gz: 485b5598534853da9cc94ce3402e8e81e1f261820208f04d4f343783cf82e231
4
+ data.tar.gz: e8ae165eb429b89065c8cb3630457bffc15d1be6a9e59826d52466f2a28b19dd
5
5
  SHA512:
6
- metadata.gz: 380993eadd3d1fc75491dda76684bed6192c9b5761b838d681f81258c844413ee70a07a2a1594a67374c45958e3c6fe3eeaf8cc54657e3ce652421e039910b42
7
- data.tar.gz: 18cd2e224c838c1efaad1c80720792af77e68efd1c52b962d272e7824401398ee81ef3acae8eb92c69947b6a25728023b95eb6064381e5cd8c5e43306b1f5e73
6
+ metadata.gz: b505c5468529bb070b6fd193a460a0252134886059b22858961f54af1932e56fb6096fe9f4fe966e32c76856cb85aad8451fa2aaf22d6c93f97f5d4722b8a92f
7
+ data.tar.gz: 35afe310870caf60d6a505c9f5839f4043014f7c651166d129116dfa012da4f54f92dd8718ca7ab74f42e9c9f0442e136331134739597e5cecd155698ca126bc
@@ -1,40 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jackhammer (1.3.4)
4
+ jackhammer (1.3.5)
5
5
  bunny (~> 2.14)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (6.0.3.1)
11
- activesupport (= 6.0.3.1)
12
- activerecord (6.0.3.1)
13
- activemodel (= 6.0.3.1)
14
- activesupport (= 6.0.3.1)
15
- activesupport (6.0.3.1)
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)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 0.7, < 2)
18
18
  minitest (~> 5.1)
19
19
  tzinfo (~> 1.1)
20
20
  zeitwerk (~> 2.2, >= 2.2.2)
21
- amq-protocol (2.3.1)
22
- ast (2.4.0)
21
+ amq-protocol (2.3.2)
22
+ ast (2.4.1)
23
23
  bunny (2.15.0)
24
24
  amq-protocol (~> 2.3, >= 2.3.1)
25
25
  bunny-mock (1.7.0)
26
26
  bunny (>= 1.7)
27
27
  byebug (11.1.3)
28
28
  concurrent-ruby (1.1.6)
29
- diff-lcs (1.3)
30
- i18n (1.8.2)
29
+ diff-lcs (1.4.4)
30
+ i18n (1.8.3)
31
31
  concurrent-ruby (~> 1.0)
32
32
  minitest (5.14.1)
33
- parallel (1.19.1)
34
- parser (2.7.1.2)
35
- ast (~> 2.4.0)
33
+ parallel (1.19.2)
34
+ parser (2.7.1.4)
35
+ ast (~> 2.4.1)
36
36
  rainbow (3.0.0)
37
37
  rake (13.0.1)
38
+ regexp_parser (1.7.1)
38
39
  rexml (3.2.4)
39
40
  rspec (3.9.0)
40
41
  rspec-core (~> 3.9.0)
@@ -49,26 +50,27 @@ GEM
49
50
  diff-lcs (>= 1.2.0, < 2.0)
50
51
  rspec-support (~> 3.9.0)
51
52
  rspec-support (3.9.3)
52
- rubocop (0.84.0)
53
+ rubocop (0.88.0)
53
54
  parallel (~> 1.10)
54
- parser (>= 2.7.0.1)
55
+ parser (>= 2.7.1.1)
55
56
  rainbow (>= 2.2.2, < 4.0)
57
+ regexp_parser (>= 1.7)
56
58
  rexml
57
- rubocop-ast (>= 0.0.3)
59
+ rubocop-ast (>= 0.1.0, < 1.0)
58
60
  ruby-progressbar (~> 1.7)
59
61
  unicode-display_width (>= 1.4.0, < 2.0)
60
- rubocop-ast (0.0.3)
62
+ rubocop-ast (0.1.0)
61
63
  parser (>= 2.7.0.1)
62
- rubocop-performance (1.6.0)
63
- rubocop (>= 0.71.0)
64
- rubocop-rspec (1.39.0)
65
- rubocop (>= 0.68.1)
64
+ rubocop-performance (1.7.0)
65
+ rubocop (>= 0.82.0)
66
+ rubocop-rspec (1.42.0)
67
+ rubocop (>= 0.87.0)
66
68
  ruby-progressbar (1.10.1)
67
69
  thread_safe (0.3.6)
68
70
  tzinfo (1.2.7)
69
71
  thread_safe (~> 0.1)
70
72
  unicode-display_width (1.7.0)
71
- zeitwerk (2.3.0)
73
+ zeitwerk (2.3.1)
72
74
 
73
75
  PLATFORMS
74
76
  ruby
data/Rakefile CHANGED
@@ -5,4 +5,4 @@ require 'rubocop/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
  RuboCop::RakeTask.new
7
7
 
8
- task default: %i[rubocop:auto_correct spec]
8
+ task default: %i[spec rubocop:auto_correct]
@@ -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
@@ -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]+/, '_').gsub(/[_]+/, '_')
10
+ "#{app_name}_#{routing_key}_q".gsub(/[^\w]+/, '_').squeeze('_')
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,70 @@
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
+ @name = :jackhammer
26
+ @env = 'production'
27
+ @path = './config/jackhammer.yml'
28
+ @description = 'Validate Jackhammer configuration'
29
+ @deps = []
30
+ yield self if block_given?
31
+ if @name.is_a?(Hash)
32
+ @deps = @name.values.first
33
+ @name = @name.keys.first
34
+ end
35
+ define
36
+ end
37
+
38
+ def define
39
+ desc @description
40
+ task @name => Array(deps) do
41
+ validator = ConfigurationValidator.new
42
+ validator.config_yaml = YAML.safe_load(File.read(@path))
43
+ validator.environment = env
44
+ validator.validate
45
+ print_results validator.errors
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def print_results(errors)
52
+ puts "Jackhammer configuration #{path}\n"
53
+ if errors.any?
54
+ puts red("Problems identified: #{errors.size}\n")
55
+ errors.each { |error| puts red(error) }
56
+ exit 1
57
+ else
58
+ puts green('OK')
59
+ end
60
+ end
61
+
62
+ def red(text)
63
+ "\e[1;31m#{text}\e[0m"
64
+ end
65
+
66
+ def green(text)
67
+ "\e[1;32m#{text}\e[0m"
68
+ end
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module Jackhammer
2
- VERSION = '1.3.4'.freeze
2
+ VERSION = '1.3.5'.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.4
4
+ version: 1.3.5
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-05-26 00:00:00.000000000 Z
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -177,11 +177,13 @@ files:
177
177
  - lib/jackhammer.rb
178
178
  - lib/jackhammer/cli.rb
179
179
  - lib/jackhammer/configuration.rb
180
+ - lib/jackhammer/configuration_validator.rb
180
181
  - lib/jackhammer/exceptions.rb
181
182
  - lib/jackhammer/log.rb
182
183
  - lib/jackhammer/message_receiver.rb
183
184
  - lib/jackhammer/queue.rb
184
185
  - lib/jackhammer/queue_name.rb
186
+ - lib/jackhammer/rake_task.rb
185
187
  - lib/jackhammer/server.rb
186
188
  - lib/jackhammer/topic.rb
187
189
  - lib/jackhammer/topic_manager.rb