rx-healthcheck 0.1.0 → 0.1.5

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: 51191dafecd2e8ad24a88a3c60a44f49618f7983ded633bf58df1f482583c6a7
4
- data.tar.gz: c283c8507f67d1e1d6012e8a94b33fb4ba17fd0724bde9e523388b28efa5b0ba
3
+ metadata.gz: 413f9d8b2e63ed831d68f8da5bfcfc32e40ca7eb93cf2b7a591c442d3bc2e205
4
+ data.tar.gz: d455aa46093f8d43b0c8be1d6464837f14603b1f44eadbf9078e1159a1bca9c3
5
5
  SHA512:
6
- metadata.gz: 7f79992064d97c64192b55378a2d5477fe11cfbfbf3aad28b92236bcaa5bcd7bb247b0df885d00c6eec17146f23620822312c39068e4dbb391d4d287a36da30f
7
- data.tar.gz: 9e4cc0de75b8b3bf88e9c4588706ecd1315051f558779e53150c615e581f8b04363731b3527134a8a35044564fd08226d14c94e3c7ba3e17491dfd7acd604291
6
+ metadata.gz: 2fdf00d9d3110daec49fef3c4aab4c1cd902d7d516283d361c5b78b28909c343d2fc1af87c4be9557b090783f3d6fbb3b17d0987e6f00ee26cad5e6d7564f488
7
+ data.tar.gz: 5f94fbdedc4f8d88b89332ffc544a2f1655a962c3f166a34f6d938c36bb77a733317cf0b4bbb6adaa76abc98a40d3ec317291ab76e3496f4600cca348cc1462c
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
9
 
10
- gem "minitest", "~> 5.0"
10
+ gem "minitest", "~> 5.0"
11
+ gem "simplecov", "0.21.2"
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rx (0.1.0)
5
- simplecov (= 0.21.2)
4
+ rx-healthcheck (0.1.4)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
@@ -23,7 +22,8 @@ PLATFORMS
23
22
  DEPENDENCIES
24
23
  minitest (~> 5.0)
25
24
  rake (~> 13.0)
26
- rx!
25
+ rx-healthcheck!
26
+ simplecov (= 0.21.2)
27
27
 
28
28
  BUNDLED WITH
29
29
  2.2.11
@@ -2,7 +2,7 @@ module Rx
2
2
  module Check
3
3
  class Result
4
4
  def self.from(check_name)
5
- start_at = Time.now
5
+ start_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
6
6
  err = nil
7
7
  result = false
8
8
 
@@ -12,7 +12,7 @@ module Rx
12
12
  err = ex
13
13
  end
14
14
 
15
- end_at = Time.now
15
+ end_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
16
16
 
17
17
  Result.new(check_name, result, ((end_at - start_at) * 1000).round(2), err)
18
18
  end
@@ -14,6 +14,10 @@ module Rx
14
14
  Future.new(&block).execute
15
15
  end
16
16
 
17
+ def self.thread_pool
18
+ @@pool
19
+ end
20
+
17
21
  def initialize(&block)
18
22
  @channel = Queue.new
19
23
  @state = :pending
@@ -25,6 +25,11 @@ module Rx
25
25
  self
26
26
  end
27
27
 
28
+ def restart
29
+ shutdown
30
+ start
31
+ end
32
+
28
33
  def started?
29
34
  pool.map(&:alive?).any?
30
35
  end
data/lib/rx/middleware.rb CHANGED
@@ -14,7 +14,7 @@ module Rx
14
14
  options: {})
15
15
  @app = app
16
16
  @options = DEFAULT_OPTIONS.merge(options)
17
- @cache = cache_factory(self.options)
17
+ @cache = cache_factory(@options)
18
18
 
19
19
  @liveness_checks = liveness
20
20
  @readiness_checks = readiness
@@ -23,11 +23,11 @@ module Rx
23
23
  end
24
24
 
25
25
  def call(env)
26
- unless health_check_request?(env)
26
+ unless health_check_request?(path(env))
27
27
  return app.call(env)
28
28
  end
29
29
 
30
- case env["REQUEST_PATH"]
30
+ case path(env)
31
31
  when "/liveness"
32
32
  ok = check_to_component(liveness_checks).map { |x| x[:status] == 200 }.all?
33
33
  liveness_response(ok)
@@ -57,14 +57,18 @@ module Rx
57
57
  Rx::Cache::InMemoryCache.new
58
58
  end
59
59
 
60
- def health_check_request?(env)
61
- %w[/liveness /readiness /deep].include?(env["REQUEST_PATH"])
60
+ def health_check_request?(path)
61
+ %w[/liveness /readiness /deep].include?(path)
62
62
  end
63
63
 
64
64
  def liveness_response(is_ok)
65
65
  [is_ok ? 200 : 503, {}, []]
66
66
  end
67
67
 
68
+ def path(env)
69
+ env["PATH_INFO"] || env["REQUEST_PATH"] || env["REQUEST_URI"]
70
+ end
71
+
68
72
  def readiness_response(components)
69
73
  status = components.map { |x| x[:status] == 200 }.all? ? 200 : 503
70
74
 
data/lib/rx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rx
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.5"
5
5
  end
data/rx.gemspec CHANGED
@@ -25,8 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_dependency "simplecov", "0.21.2"
29
-
30
28
  # For more information and examples about making a new gem, checkout our
31
29
  # guide at: https://bundler.io/guides/creating_gem.html
32
30
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rx-healthcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Pendleton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-25 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: simplecov
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '='
18
- - !ruby/object:Gem::Version
19
- version: 0.21.2
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '='
25
- - !ruby/object:Gem::Version
26
- version: 0.21.2
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description:
28
14
  email:
29
15
  - zachpendleton@gmail.com