Skip to content

Commit

Permalink
feat(stop): allow to also cancel any ongoing deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
davlgd authored and hsablonniere committed Jul 1, 2024
1 parent 7d1c56a commit 9f9b075
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion bin/clever.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ function run () {
}),
exitOnDeploy: getExitOnOption(),
sameCommitPolicy: getSameCommitPolicyOption(),
stopAll: cliparse.flag('all', {
description: 'Stop application and any ongoing deployment',
}),
webhookFormat: cliparse.option('format', {
metavar: 'format',
default: 'raw',
Expand Down Expand Up @@ -1038,7 +1041,7 @@ function run () {
const stop = lazyRequirePromiseModule('../src/commands/stop.js');
const stopCommand = cliparse.command('stop', {
description: 'Stop a running application',
options: [opts.alias, opts.appIdOrName],
options: [opts.alias, opts.appIdOrName, opts.stopAll],
}, stop('stop'));

// TCP-REDIRS COMMAND
Expand Down
13 changes: 12 additions & 1 deletion src/commands/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ const Application = require('../models/application.js');
const application = require('@clevercloud/client/cjs/api/v2/application.js');
const Logger = require('../logger.js');
const { sendToApi } = require('../models/send-to-api.js');
const { getAllDeployments, cancelDeployment } = require('@clevercloud/client/cjs/api/v2/application.js');

async function stop (params) {
const { alias, app: appIdOrName } = params.options;
const { alias, app: appIdOrName, all } = params.options;
const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);

await application.undeploy({ id: ownerId, appId }).then(sendToApi);
Logger.println('App successfully stopped!');

if (all) {
const deployments = await getAllDeployments({ id: ownerId, appId, limit: 1 }).then(sendToApi);
if (deployments.length !== 0 && deployments[0].state === 'WIP') {
const deploymentId = deployments[0].id;
await cancelDeployment({ id: ownerId, appId, deploymentId }).then(sendToApi);
Logger.println(`Deployment ${deploymentId} cancelled!`);
}

}
}

module.exports = { stop };

0 comments on commit 9f9b075

Please sign in to comment.