Skip to content

Commit 028e125

Browse files
committed
Fix heroku client bits
to reintroduce the methods used by bin/heroku-wait-deploy-scale
1 parent f8f20bd commit 028e125

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

.rubocop_todo.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2018-11-30 09:10:04 -0500 using RuboCop version 0.60.0.
3+
# on 2018-12-07 00:06:34 -0500 using RuboCop version 0.60.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -16,7 +16,7 @@ Metrics/AbcSize:
1616
Metrics/BlockLength:
1717
Max: 30
1818

19-
# Offense count: 1
19+
# Offense count: 2
2020
# Configuration parameters: CountComments.
2121
Metrics/ClassLength:
2222
Max: 138
@@ -25,7 +25,7 @@ Metrics/ClassLength:
2525
Metrics/CyclomaticComplexity:
2626
Max: 7
2727

28-
# Offense count: 27
28+
# Offense count: 30
2929
# Configuration parameters: CountComments, ExcludedMethods.
3030
Metrics/MethodLength:
3131
Max: 81
@@ -55,7 +55,7 @@ Style/RegexpLiteral:
5555
Exclude:
5656
- 'bin/travis-worker-verify-config'
5757

58-
# Offense count: 7
58+
# Offense count: 9
5959
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
6060
# URISchemes: http, https
6161
Metrics/LineLength:

lib/heroku_client.rb

+68
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,74 @@ def initialize(api_key: ENV.fetch('HEROKU_API_KEY', ''),
1515
private :api_key
1616
private :api_host
1717

18+
def wait(heroku_app, timeout: 120)
19+
c = 0
20+
21+
loop do
22+
return true if get("/apps/#{heroku_app}")
23+
return false if c >= timeout
24+
25+
sleep 10
26+
c += 10
27+
end
28+
29+
true
30+
end
31+
32+
def deploy(repo_slug, heroku_app, version)
33+
warn "\nDeploying #{repo_slug} #{version} to #{heroku_app}"
34+
35+
response = post(
36+
JSON.generate(
37+
'source_blob' => {
38+
'url' => "https://github.com/#{repo_slug}/archive/#{version}.tar.gz",
39+
'version' => version
40+
}
41+
),
42+
"/apps/#{heroku_app}/builds"
43+
)
44+
45+
raise 'Could not request a deployment' if response.nil?
46+
47+
warn "\nStreaming deploy output"
48+
49+
raise 'Could not stream deployment output' unless stream(URI(response.fetch('output_stream_url')))
50+
end
51+
52+
def scale(heroku_app, ps_scales)
53+
Array(ps_scales).each do |ps_scale|
54+
formation = parse_formation(ps_scale)
55+
response = patch(
56+
JSON.generate(
57+
'quantity' => formation.fetch(:qty),
58+
'size' => formation.fetch(:size)
59+
),
60+
"/apps/#{heroku_app}/formation/#{formation.fetch(:type)}"
61+
)
62+
raise "Could not scale #{heroku_app} #{ps_scales.inspect}" if response.nil?
63+
64+
warn "---> scaled #{heroku_app} #{ps_scale}:"
65+
warn JSON.pretty_generate(response)
66+
end
67+
end
68+
69+
def parse_formation(ps_scale)
70+
ret = {
71+
type: '',
72+
qty: 0,
73+
size: ''
74+
}
75+
76+
parts = ps_scale.split('=', 2)
77+
ret[:type] = parts.fetch(0)
78+
79+
subparts = parts.fetch(1).split(':', 2)
80+
ret[:qty] = Integer(subparts.fetch(0))
81+
ret[:size] = subparts.fetch(1).strip
82+
83+
ret
84+
end
85+
1886
def get(path)
1987
request(Net::HTTP::Get.new(path))
2088
end

0 commit comments

Comments
 (0)