rails_health_checks 1.2.0 → 1.2.1

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: 9033111f01524e17546525feaba1a215ac6e3cad1c7c8b0b12dd527850c74e7f
4
- data.tar.gz: 3eded20b26844b046d33689f6a5512efa1a7c7964f04679552d00020d9a7aa78
3
+ metadata.gz: 9bff80f924f018abcc0f67cf61568e29e7aff6e25c9e9c227aaa830290209918
4
+ data.tar.gz: 065ee72ad6e12c56d5dc4d6bd1e527e35a7e546a7c85cacbd5dedc13ecf64e9a
5
5
  SHA512:
6
- metadata.gz: 7a8373f504fde389fd3e0202f3a08a1ea9e5a6af15dca997f8270e8dfcbca2cf5155a5f57a490392c6df1d3bc65f15a452b1c64ba3f96650b214007be5506623
7
- data.tar.gz: 3f58fb48bd0a1a416e078f3e3bae0bb70e9e220c1cb93eaae25b2ec1c7710d56c9965e965fffa33f6d3922c132a120f8e0b554c18358d10eaa0787cebad0b778
6
+ metadata.gz: 7a362e27a106bd832c43c2c9a79989e38f26eeb7ce5c1027e2877a3e99ac0ca6f95dca653874bf9ec70edad261a68214e502d930c99f29238c67a2c4d755141c
7
+ data.tar.gz: 4367170dcd946c7f5e20c056f3596cad8a2a01c187aa67ebf582ae38d39c4e55c977b0f45ec1fb002bdafa9cbbbecb8aad32f7a4a7b005d9aa0e209cd98333ba
data/Rakefile CHANGED
@@ -11,7 +11,12 @@ RuboCop::RakeTask.new(:lint)
11
11
  Bundler::Audit::Task.new
12
12
  RSpec::Core::RakeTask.new(:spec)
13
13
 
14
- task default: [:lint, :'bundle:audit:update', 'bundle:audit:check', :spec]
14
+ desc "Run Brakeman static security analysis"
15
+ task :brakeman do
16
+ sh "bundle exec brakeman -q --no-pager --force-scan --skip-files spec/ ."
17
+ end
18
+
19
+ task default: [:lint, :'bundle:audit:update', 'bundle:audit:check', :brakeman, :spec]
15
20
 
16
21
  desc "Run performance benchmarks"
17
22
  task :benchmark do
@@ -51,9 +51,11 @@ module RailsHealthChecks
51
51
  t = check.timeout || timeout
52
52
  Concurrent::Future.execute { run_check(check, timeout: t) }
53
53
  end
54
- checks.each do |name, check|
55
- t = check.timeout || timeout
56
- results[name] = futures[name].value(t + 1) || mark_critical(check, "timed out")
54
+ permit_concurrent_loads do
55
+ checks.each do |name, check|
56
+ t = check.timeout || timeout
57
+ results[name] = futures[name].value(t + 1) || mark_critical(check, "timed out")
58
+ end
57
59
  end
58
60
  if payload
59
61
  payload[:status] = overall_status(results)
@@ -69,21 +71,45 @@ module RailsHealthChecks
69
71
  if defined?(ActiveSupport::Notifications)
70
72
  ActiveSupport::Notifications.instrument("health_check.rails_health_checks", &block)
71
73
  else
72
- # :nocov:
74
+ # simplecov:disable
73
75
  yield nil
74
- # :nocov:
76
+ # simplecov:enable
75
77
  end
76
78
  end
77
79
 
78
80
  def self.run_check(check, timeout:)
79
- Timeout.timeout(timeout) { check.call }
80
- check
81
+ with_executor do
82
+ Timeout.timeout(timeout) { check.call }
83
+ check
84
+ end
81
85
  rescue Timeout::Error
82
86
  mark_critical(check, "timed out")
83
87
  rescue StandardError => e
84
88
  mark_critical(check, e.message)
85
89
  end
86
90
 
91
+ # Checks run on Concurrent's global pool, outside the request thread. Wrapping
92
+ # each one in the Rails executor returns any Active Record connections it
93
+ # leased (primary, cache, queue, ...) when the check finishes, including on
94
+ # timeout; otherwise they stay checked out by the long-lived pool thread.
95
+ def self.with_executor(&block)
96
+ if defined?(Rails) && Rails.application
97
+ Rails.application.executor.wrap(&block)
98
+ else
99
+ yield
100
+ end
101
+ end
102
+
103
+ # In development the request thread holds the autoload interlock while it
104
+ # waits on the futures; the check threads need it to load code, so let them.
105
+ def self.permit_concurrent_loads(&block)
106
+ if defined?(ActiveSupport::Dependencies) && ActiveSupport::Dependencies.respond_to?(:interlock)
107
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads(&block)
108
+ else
109
+ yield
110
+ end
111
+ end
112
+
87
113
  def self.mark_critical(check, message)
88
114
  check.instance_variable_set(:@status, "critical")
89
115
  check.instance_variable_set(:@message, message)
@@ -98,6 +124,6 @@ module RailsHealthChecks
98
124
  end
99
125
  end
100
126
 
101
- private_class_method :run_check, :mark_critical, :overall_status, :instrument
127
+ private_class_method :run_check, :with_executor, :permit_concurrent_loads, :mark_critical, :overall_status, :instrument
102
128
  end
103
129
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsHealthChecks
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_health_checks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck Smith