-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathdisable.ts
40 lines (32 loc) · 1.18 KB
/
disable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {Command, flags} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import {ux} from '@oclif/core'
const METRICS_HOST = 'api.metrics.heroku.com'
export default class Disable extends Command {
static description = 'disable web dyno autoscaling'
static flags = {
app: flags.app({required: true}),
remote: flags.remote(),
}
async run() {
const {flags} = await this.parse(Disable)
ux.action.start('Disabling dyno autoscaling')
const appResponse = await this.heroku.get<Heroku.App>(`/apps/${flags.app}`)
const app = appResponse.body
const monitorsResponse = await this.heroku.get<Heroku.Formation>(`/apps/${app.id}/formation/web/monitors`, {
hostname: METRICS_HOST,
})
const monitors = monitorsResponse.body
const scaleMonitor = monitors.find((m: any) => m.action_type === 'scale')
if (!scaleMonitor) throw new Error(`${flags.app} does not have autoscale enabled`)
await this.heroku.patch(`/apps/${app.id}/formation/web/monitors/${scaleMonitor.id}`, {
hostname: METRICS_HOST,
body: {
is_active: false,
period: 1,
op: 'GREATER_OR_EQUAL',
},
})
ux.action.stop()
}
}