redis_cloud_auto_upgrade 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis_cloud_auto_upgrade.rb +28 -31
- data/lib/redis_cloud_auto_upgrade/class_methods.rb +10 -0
- data/lib/redis_cloud_auto_upgrade/configuration.rb +2 -1
- data/lib/redis_cloud_auto_upgrade/dependent_values.rb +25 -0
- data/lib/redis_cloud_auto_upgrade/exceptions.rb +1 -0
- data/lib/redis_cloud_auto_upgrade/heroku_api.rb +86 -83
- data/lib/redis_cloud_auto_upgrade/version.rb +2 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 494f5b0990ddbf04156d7d310084dcd1baacbe60
|
4
|
+
data.tar.gz: 551620dfdcb94c70813279385311f7ce5c419a43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d09a535c278efa6d9989553683a6d6013962c17a1c356b4a88fbe04d9113b7f18455a97f1bdd3fad4c38b6c287ad52f15894de68327ec2a83aaf55f168558a9
|
7
|
+
data.tar.gz: 20abd85a69edcb43abca63d2afc5686b565a92b0dd082fe9c46fd9b6946d2184cc12b1b5ebc9ef4e1c71eb8fc34e9ee50a9918c48610b307d191de4da8bd2ab2
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative './redis_cloud_auto_upgrade/version'
|
2
3
|
require_relative './redis_cloud_auto_upgrade/exceptions'
|
3
4
|
require_relative './redis_cloud_auto_upgrade/configuration'
|
5
|
+
require_relative './redis_cloud_auto_upgrade/dependent_values'
|
6
|
+
require_relative './redis_cloud_auto_upgrade/class_methods'
|
4
7
|
|
5
8
|
require_relative './redis_cloud_auto_upgrade/heroku_api'
|
6
9
|
|
@@ -8,14 +11,12 @@ require 'redis'
|
|
8
11
|
|
9
12
|
# See README.md for details
|
10
13
|
class RedisCloudAutoUpgrade
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end # class << self
|
14
|
+
include self::DependentValues
|
15
|
+
extend self::ClassMethods
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@config = Configuration.new
|
19
|
+
end
|
19
20
|
|
20
21
|
def configure(config)
|
21
22
|
@config.configure config
|
@@ -24,7 +25,7 @@ class RedisCloudAutoUpgrade
|
|
24
25
|
|
25
26
|
def current_redis_cloud_plan
|
26
27
|
@__current_redis_cloud_plan ||=
|
27
|
-
|
28
|
+
HerokuAPI.current_redis_cloud_plan(**heroku_params)
|
28
29
|
end
|
29
30
|
|
30
31
|
# Memoize from lab42_core gem?
|
@@ -35,29 +36,23 @@ class RedisCloudAutoUpgrade
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def needs_to_upgrade?
|
38
|
-
!(current_redis_mem_usage <
|
39
|
+
!(current_redis_mem_usage < currently_available_memory * config.treshhold)
|
39
40
|
end
|
40
41
|
|
41
42
|
def potential_upgrade!
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
fail IllegalConfiguration, config.errors_human_readable
|
46
|
-
end
|
43
|
+
raise IllegalConfiguration, config.errors_human_readable unless config.valid?
|
44
|
+
do_potential_upgrade!
|
47
45
|
end
|
48
46
|
|
49
47
|
private
|
50
48
|
|
51
|
-
def initialize
|
52
|
-
@config = Configuration.new
|
53
|
-
end
|
54
|
-
|
55
49
|
attr_reader :config
|
56
50
|
|
57
51
|
def currently_available_memory
|
58
52
|
@__currently_available_memory__ ||=
|
59
53
|
HerokuAPI.currently_available_memory(
|
60
|
-
**config.only(:heroku_api_key, :heroku_app_name)
|
54
|
+
**config.only(:heroku_api_key, :heroku_app_name)
|
55
|
+
)
|
61
56
|
end
|
62
57
|
|
63
58
|
def do_potential_upgrade!
|
@@ -65,7 +60,7 @@ class RedisCloudAutoUpgrade
|
|
65
60
|
do_upgrade!
|
66
61
|
true
|
67
62
|
else
|
68
|
-
|
63
|
+
info_no_upgrade
|
69
64
|
false
|
70
65
|
end
|
71
66
|
end
|
@@ -85,7 +80,7 @@ upgraded RedisCloud plan for app: #{config.heroku_app_name}
|
|
85
80
|
mem usage was approximately #{current_redis_mem_usage / 1_000_000}MB
|
86
81
|
old_plan was #{old_plan}
|
87
82
|
new_plan is #{new_plan}
|
88
|
-
|
83
|
+
EOS
|
89
84
|
end
|
90
85
|
|
91
86
|
def heroku_params
|
@@ -98,9 +93,16 @@ new_plan is #{new_plan}
|
|
98
93
|
config.logger.info([self.class.name, str].join(' '))
|
99
94
|
end
|
100
95
|
|
101
|
-
def
|
102
|
-
|
103
|
-
|
96
|
+
def info_no_upgrade
|
97
|
+
msg = format(
|
98
|
+
'no upgrade needed %s mem usage %dMB or %d%%, treshhold: %d%%, current plan: %s',
|
99
|
+
config.heroku_app_name,
|
100
|
+
current_redis_mem_usage_megab,
|
101
|
+
current_redis_mem_usage_percent,
|
102
|
+
treshhold_in_percent,
|
103
|
+
current_redis_cloud_plan
|
104
|
+
)
|
105
|
+
info msg
|
104
106
|
end
|
105
107
|
|
106
108
|
def update_data(old_plan, new_plan)
|
@@ -109,13 +111,8 @@ new_plan is #{new_plan}
|
|
109
111
|
new_plan: new_plan,
|
110
112
|
upgraded_at: Time.now,
|
111
113
|
mem_usage: current_redis_mem_usage,
|
112
|
-
mem_usage_in_percent:
|
114
|
+
mem_usage_in_percent: current_redis_mem_usage_percent,
|
113
115
|
treshhold_in_percent: treshhold_in_percent
|
114
116
|
)
|
115
117
|
end
|
116
|
-
|
117
|
-
def treshhold_in_percent
|
118
|
-
@__treshhold_in_percent__ ||=
|
119
|
-
(config.treshhold * 100).round
|
120
|
-
end
|
121
118
|
end # class RedisCloudAutoUpgrade
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# Configuration part
|
2
3
|
class RedisCloudAutoUpgrade
|
3
4
|
Configuration = Struct.new(
|
@@ -18,7 +19,7 @@ class RedisCloudAutoUpgrade
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def only(*keys)
|
21
|
-
keys.inject({})do |h, k|
|
22
|
+
keys.inject({}) do |h, k|
|
22
23
|
h.merge(k => send(k))
|
23
24
|
end
|
24
25
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Extracting behavior for compution of
|
3
|
+
# dependent values
|
4
|
+
module RedisCloudAutoUpgrade::DependentValues
|
5
|
+
private
|
6
|
+
|
7
|
+
def current_redis_mem_usage_megab
|
8
|
+
@__current_redis_mem_usage_megab__ ||=
|
9
|
+
current_redis_mem_usage / 1_000_000
|
10
|
+
rescue
|
11
|
+
0
|
12
|
+
end
|
13
|
+
|
14
|
+
def current_redis_mem_usage_percent
|
15
|
+
@__current_redis_mem_usage_percent__ ||=
|
16
|
+
current_redis_mem_usage * 100 / currently_available_memory
|
17
|
+
rescue
|
18
|
+
0
|
19
|
+
end
|
20
|
+
|
21
|
+
def treshhold_in_percent
|
22
|
+
@__treshhold_in_percent__ ||=
|
23
|
+
(config.treshhold * 100).round
|
24
|
+
end
|
25
|
+
end
|
@@ -1,99 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'platform-api'
|
2
3
|
# A function wrapper accessing the Heroku Platform API in a functional way
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
fail ArgumentError, "the plan #{plan.inspect} does not exist"
|
10
|
-
end
|
4
|
+
module RedisCloudAutoUpgrade::HerokuAPI
|
5
|
+
class << self
|
6
|
+
def available_memory(plan)
|
7
|
+
plan_memory
|
8
|
+
.fetch(plan) do
|
9
|
+
raise ArgumentError, "the plan #{plan.inspect} does not exist"
|
11
10
|
end
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
def current_redis_cloud_plan(heroku_api_key:, heroku_app_name:)
|
14
|
+
heroku(heroku_api_key)
|
15
|
+
.addon
|
16
|
+
.list_by_app(heroku_app_name)
|
17
|
+
.find(&select_redis_cloud_addon)['plan']['name']
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
def currently_available_memory(heroku_api_key:, heroku_app_name:)
|
21
|
+
available_memory(
|
22
|
+
current_redis_cloud_plan(
|
23
|
+
heroku_api_key: heroku_api_key, heroku_app_name: heroku_app_name
|
24
|
+
)
|
25
|
+
)
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
def next_plan_to_upgrade_to(heroku_api_key:, heroku_app_name:)
|
29
|
+
next_plan(
|
30
|
+
current_redis_cloud_plan(
|
31
|
+
heroku_api_key: heroku_api_key, heroku_app_name: heroku_app_name
|
32
|
+
)
|
33
|
+
)
|
34
|
+
end
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def upgrade_plan!(heroku_api_key:, heroku_app_name:)
|
37
|
+
next_plan =
|
38
|
+
next_plan_to_upgrade_to(heroku_api_key: heroku_api_key, heroku_app_name: heroku_app_name)
|
39
|
+
heroku(heroku_api_key)
|
40
|
+
.addon
|
41
|
+
.update(heroku_app_name, 'rediscloud', plan: next_plan)
|
42
|
+
next_plan
|
43
|
+
end
|
40
44
|
|
41
|
-
|
45
|
+
private
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
def heroku(api_key)
|
48
|
+
PlatformAPI.connect api_key
|
49
|
+
end
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
51
|
+
def next_plan(plan)
|
52
|
+
plan_transitions
|
53
|
+
.fetch(plan) do
|
54
|
+
raise ArgumentError, "the plan #{plan.inspect} does not exist or cannot be upgraded"
|
52
55
|
end
|
56
|
+
end
|
53
57
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
58
|
+
# rubocop:disable Metrics/MethodLength
|
59
|
+
def plan_transitions
|
60
|
+
{
|
61
|
+
'rediscloud:30' => 'rediscloud:100',
|
62
|
+
'rediscloud:100' => 'rediscloud:250',
|
63
|
+
'rediscloud:250' => 'rediscloud:500',
|
64
|
+
'rediscloud:500' => 'rediscloud:1000',
|
65
|
+
'rediscloud:1000' => 'rediscloud:2500',
|
66
|
+
'rediscloud:2500' => 'rediscloud:5000',
|
67
|
+
'rediscloud:5000' => 'rediscloud:10000',
|
68
|
+
'rediscloud:10000' => 'rediscloud:15000',
|
69
|
+
'rediscloud:15000' => 'rediscloud:20000',
|
70
|
+
'rediscloud:20000' => 'rediscloud:25000',
|
71
|
+
'rediscloud:25000' => 'rediscloud:50000'
|
72
|
+
}
|
73
|
+
end
|
70
74
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
75
|
+
def plan_memory
|
76
|
+
{
|
77
|
+
'rediscloud:30' => 30_000_000,
|
78
|
+
'rediscloud:100' => 100_000_000,
|
79
|
+
'rediscloud:250' => 250_000_000,
|
80
|
+
'rediscloud:500' => 500_000_000,
|
81
|
+
'rediscloud:1000' => 1_000_000_000,
|
82
|
+
'rediscloud:2500' => 2_500_000_000,
|
83
|
+
'rediscloud:5000' => 5_000_000_000,
|
84
|
+
'rediscloud:10000' => 10_000_000_000,
|
85
|
+
'rediscloud:15000' => 15_000_000_000,
|
86
|
+
'rediscloud:20000' => 20_000_000_000,
|
87
|
+
'rediscloud:25000' => 25_000_000_000,
|
88
|
+
'rediscloud:50000' => 50_000_000_000
|
89
|
+
}
|
90
|
+
end
|
87
91
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
92
|
+
def select_redis_cloud_addon
|
93
|
+
lambda do |addon|
|
94
|
+
begin
|
95
|
+
addon['addon_service']['name'] == 'rediscloud'
|
96
|
+
rescue
|
97
|
+
nil
|
95
98
|
end
|
96
99
|
end
|
97
|
-
end
|
98
|
-
end #
|
99
|
-
end # class RCAU
|
100
|
+
end
|
101
|
+
end # class << self
|
102
|
+
end # class RCAU::HerokuApi
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_cloud_auto_upgrade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.40.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.40.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: timecop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,7 +132,9 @@ files:
|
|
132
132
|
- LICENSE
|
133
133
|
- README.md
|
134
134
|
- lib/redis_cloud_auto_upgrade.rb
|
135
|
+
- lib/redis_cloud_auto_upgrade/class_methods.rb
|
135
136
|
- lib/redis_cloud_auto_upgrade/configuration.rb
|
137
|
+
- lib/redis_cloud_auto_upgrade/dependent_values.rb
|
136
138
|
- lib/redis_cloud_auto_upgrade/exceptions.rb
|
137
139
|
- lib/redis_cloud_auto_upgrade/heroku_api.rb
|
138
140
|
- lib/redis_cloud_auto_upgrade/version.rb
|
@@ -148,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
150
|
requirements:
|
149
151
|
- - ">="
|
150
152
|
- !ruby/object:Gem::Version
|
151
|
-
version: 2.
|
153
|
+
version: 2.3.1
|
152
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
155
|
requirements:
|
154
156
|
- - ">="
|