Skip to content

Commit

Permalink
Handle deployment cancellation (#3823)
Browse files Browse the repository at this point in the history
Co-authored-by: Max <8418866+rdev@users.noreply.github.com>
  • Loading branch information
Ana Trajkovska and rdev committed Feb 26, 2020
1 parent 1656c98 commit fd964f8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/now-cli/src/commands/deploy/latest.js
Expand Up @@ -566,6 +566,11 @@ export default async function main(
return 1;
}

if (deployment.readyState === 'CANCELED') {
output.log('The deployment has been canceled');
return 1;
}

const deploymentResponse = await getDeploymentByIdOrHost(
now,
contextName,
Expand Down
7 changes: 7 additions & 0 deletions packages/now-cli/src/util/deploy/process-deployment.ts
Expand Up @@ -202,6 +202,13 @@ export default async function processDeployment({
}
}

if (event.type === 'canceled') {
if (buildSpinner) {
buildSpinner();
}
return event.payload;
}

if (event.type === 'ready') {
if (queuedSpinner) {
queuedSpinner();
Expand Down
9 changes: 9 additions & 0 deletions packages/now-client/src/check-deployment-status.ts
Expand Up @@ -77,6 +77,15 @@ export async function* checkDeploymentStatus(
yield { type: 'building', payload: deploymentUpdate };
}

if (
deploymentUpdate.readyState === 'CANCELED' &&
!finishedEvents.has('canceled')
) {
debug('Deployment state changed to CANCELED');
finishedEvents.add('canceled');
yield { type: 'canceled', payload: deploymentUpdate };
}

if (isReady(deploymentUpdate) && !finishedEvents.has('ready')) {
debug('Deployment state changed to READY');
finishedEvents.add('ready');
Expand Down
1 change: 1 addition & 0 deletions packages/now-client/src/utils/index.ts
Expand Up @@ -29,6 +29,7 @@ const EVENTS_ARRAY = [
'error',
'notice',
'tip',
'canceled',
] as const;

export type DeploymentEventType = (typeof EVENTS_ARRAY)[number];
Expand Down

0 comments on commit fd964f8

Please sign in to comment.