ready-for-migration 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/app/controllers/concerns/ready/for/migration/health_action_inspectable.rb +112 -0
- data/app/controllers/ready/for/migration/health_controller.rb +1 -0
- data/lib/ready/for/migration/engine.rb +5 -0
- data/lib/ready/for/migration/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f855a777fcbf390d9e7df10b5a2a8b0002623c9b9985a254f7d79f2d25f93990
|
4
|
+
data.tar.gz: '052758f3910e9864972b96ec3d7d46ea637416a57ca4fad205f91efda59c7709'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11036a04db24b448d2d06efda25638cbd605e764be39cd12245717e3914ff12c10f92524cc6bde17d6ec5a33f1a9be30c47d3c57a249395f93283fccd983be27
|
7
|
+
data.tar.gz: 5bf2c1b2beae4df61c6e0f59b007035c9af90fa35ebd2648d6e2c0d5f8eb41e7252e38771df396e2f350dce3c419315ad330a5cef64f594ca2f9c7e9521456c4
|
data/README.md
CHANGED
@@ -29,5 +29,23 @@ Or install it yourself as:
|
|
29
29
|
$ gem install ready-for-migration
|
30
30
|
```
|
31
31
|
|
32
|
+
## Simulate Health Check Response
|
33
|
+
|
34
|
+
You can simulate health check response by adding specific query parameters to your health check requests.
|
35
|
+
|
36
|
+
Here's the pattern we're providing. (values are just an example)
|
37
|
+
|
38
|
+
|pattern|behavior|
|
39
|
+
|--|--|
|
40
|
+
|No query parameters|health check as usual.|
|
41
|
+
|`?status=503`|respond with specified status code.|
|
42
|
+
|`?status=503&after=60`|respond with specified status code once specified seconds have passed since the first access with `after`.|
|
43
|
+
|`?status=503&sleep=60`|respond with specified status code after sleeping specified seconds.|
|
44
|
+
|`?status=503&random=10` |randomly respond with specified status code, once in a specified number as `random`.|
|
45
|
+
|`?sleep=60` |health check after sleeping specified seconds.|
|
46
|
+
|
47
|
+
NOTE: Other patterns than listed in the above example will be ignored.
|
48
|
+
NOTE: "sleep" parameter is disabled in default for avoiding DoS attack. To enabling this, you set environment variables "RFM_ENABLE_SLEEP" as "1".
|
49
|
+
|
32
50
|
## License
|
33
51
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'active_support/cache/file_store'
|
2
|
+
|
3
|
+
module Ready
|
4
|
+
module For
|
5
|
+
module Migration
|
6
|
+
module HealthActionInspectable
|
7
|
+
|
8
|
+
def self.cache
|
9
|
+
@cache ||= ActiveSupport::Cache::MemoryStore.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.sleep_enabled?
|
13
|
+
return false if ENV['RFM_ENABLE_SLEEP'].nil?
|
14
|
+
b = [ false, 0,
|
15
|
+
"0", :"0",
|
16
|
+
"f", :f,
|
17
|
+
"F", :F,
|
18
|
+
"false", :false,
|
19
|
+
"FALSE", :FALSE,
|
20
|
+
"off", :off,
|
21
|
+
"OFF", :OFF,
|
22
|
+
].include?(ENV['RFM_ENABLE_SLEEP'])
|
23
|
+
return !b
|
24
|
+
end
|
25
|
+
|
26
|
+
def readiness
|
27
|
+
if params.has_key?(:status)
|
28
|
+
case
|
29
|
+
when params.has_key?(:after)
|
30
|
+
perform_inspection_with_status_and_after
|
31
|
+
when params.has_key?(:sleep)
|
32
|
+
perform_inspection_with_status_and_sleep
|
33
|
+
when params.has_key?(:random)
|
34
|
+
perform_inspection_with_status_and_random
|
35
|
+
else
|
36
|
+
perform_inspection_with_status
|
37
|
+
end
|
38
|
+
elsif params.has_key?(:sleep)
|
39
|
+
perform_inspection_with_sleep
|
40
|
+
end
|
41
|
+
|
42
|
+
super unless performed?
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def get_status_value
|
48
|
+
raw = params.dig(:status)
|
49
|
+
status = raw.to_i if raw && /^\d{3}$/.match?(raw)
|
50
|
+
status
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_after_value
|
54
|
+
raw = params.dig(:after)
|
55
|
+
value = raw.to_i if raw && /^\d+$/.match?(raw)
|
56
|
+
value
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_random_value
|
60
|
+
raw = params.dig(:random)
|
61
|
+
value = raw.to_i if raw && /^\d+$/.match?(raw)
|
62
|
+
value
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_sleep_value
|
66
|
+
raw = params.dig(:sleep)
|
67
|
+
value = raw.to_i if raw && /^\d+$/.match?(raw)
|
68
|
+
value
|
69
|
+
end
|
70
|
+
|
71
|
+
def perform_inspection_with_status_and_after
|
72
|
+
return unless status = get_status_value
|
73
|
+
return unless value = get_after_value
|
74
|
+
|
75
|
+
first_access_time = Ready::For::Migration::HealthActionInspectable.cache.fetch(:first_access_time) { Time.now }
|
76
|
+
if first_access_time + value < Time.now
|
77
|
+
head status
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def perform_inspection_with_status_and_sleep
|
82
|
+
return unless status = get_status_value
|
83
|
+
return unless value = get_sleep_value
|
84
|
+
|
85
|
+
sleep(value) if Ready::For::Migration::HealthActionInspectable.sleep_enabled?
|
86
|
+
head status
|
87
|
+
end
|
88
|
+
|
89
|
+
def perform_inspection_with_status_and_random
|
90
|
+
return unless status = get_status_value
|
91
|
+
return unless value = get_random_value
|
92
|
+
|
93
|
+
if value == 1 || rand(value - 1) == 0
|
94
|
+
head status
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def perform_inspection_with_status
|
99
|
+
return unless status = get_status_value
|
100
|
+
head status
|
101
|
+
end
|
102
|
+
|
103
|
+
def perform_inspection_with_sleep
|
104
|
+
return unless value = get_sleep_value
|
105
|
+
|
106
|
+
sleep(value) if Ready::For::Migration::HealthActionInspectable.sleep_enabled?
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -2,6 +2,11 @@ module Ready
|
|
2
2
|
module For
|
3
3
|
module Migration
|
4
4
|
class Engine < ::Rails::Engine
|
5
|
+
|
6
|
+
initializer 'ready-for-migration.initialize_cache' do
|
7
|
+
require config.root.join('app/controllers/concerns/ready/for/migration/health_action_inspectable')
|
8
|
+
Ready::For::Migration::HealthActionInspectable.cache.write(:first_access_time, Time.now)
|
9
|
+
end
|
5
10
|
end
|
6
11
|
end
|
7
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ready-for-migration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bizside-developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- MIT-LICENSE
|
61
61
|
- README.md
|
62
62
|
- Rakefile
|
63
|
+
- app/controllers/concerns/ready/for/migration/health_action_inspectable.rb
|
63
64
|
- app/controllers/ready/for/migration/health_controller.rb
|
64
65
|
- config/routes.rb
|
65
66
|
- lib/ready/for/migration.rb
|
@@ -84,8 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
85
|
- !ruby/object:Gem::Version
|
85
86
|
version: '0'
|
86
87
|
requirements: []
|
87
|
-
|
88
|
-
rubygems_version: 2.7.6.2
|
88
|
+
rubygems_version: 3.1.6
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: ready for migration
|