Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add fir-specific error message for autoscale:enable #3069

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions packages/cli/src/commands/ps/autoscale/enable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Command, flags} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import {ux} from '@oclif/core'
import {App, Formation} from '../../../lib/types/fir'

const METRICS_HOST = 'api.metrics.heroku.com'

Expand All @@ -26,12 +27,25 @@ export default class Enable extends Command {
ux.action.start('Enabling dyno autoscaling')

const [appResponse, formationResponse] = await Promise.all([
this.heroku.get<Heroku.App>(`/apps/${flags.app}`),
this.heroku.get<Heroku.Formation[]>(`/apps/${flags.app}/formation`),
this.heroku.get<App>(`/apps/${flags.app}`, {
headers: {
Accept: 'application/vnd.heroku+json; version=3.sdk',
},
}),
this.heroku.get<Formation[]>(`/apps/${flags.app}/formation`, {
headers: {
Accept: 'application/vnd.heroku+json; version=3.sdk',
},
}),
])
const app = appResponse.body
const formations = formationResponse.body
const webFormation = formations.find((f: any) => f.type === 'web')

if (app.generation === 'fir') {
throw new Error('Autoscaling is unavailable for apps in this space. See https://devcenter.heroku.com/articles/generations.')
k80bowman marked this conversation as resolved.
Show resolved Hide resolved
}

if (!webFormation) throw new Error(`${flags.app} does not have any web dynos to scale`)

const {size} = webFormation
Expand Down
16 changes: 15 additions & 1 deletion packages/cli/test/unit/commands/ps/enable.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function commonSetup() {
.stderr()
.nock(API_HOST, api => api
.get(`/apps/${APP_NAME}`)
.reply(200, {id: APP_ID, name: APP_NAME}),
.reply(200, {id: APP_ID, name: APP_NAME, generation: 'cedar'}),
)
}

Expand Down Expand Up @@ -131,3 +131,17 @@ describe('with a Hobby dyno', function () {
.catch(error => expect(error.message).to.contain('Autoscaling is only available with Performance or Private dynos'))
.it('rejected non-performance dynos')
})

describe('with a fir app', function () {
test
.stderr()
.nock(API_HOST, api => api
.get(`/apps/${APP_NAME}`)
.reply(200, {id: APP_ID, name: APP_NAME, generation: 'fir'})
.get(`/apps/${APP_NAME}/formation`)
.reply(200, [{id: FORMATION_ID, type: 'web', size: 'Performance-L'}]),
)
.command(['ps:autoscale:enable', '--min', '1', '--max', '2', '--app', APP_NAME])
.catch(error => expect(error.message).to.contain('Autoscaling is unavailable for apps in this space. See https://devcenter.heroku.com/articles/generations.'))
.it('rejected fir app')
})
Loading