Skip to content

Commit d8e22d7

Browse files
committed
feat(cli): Updating function deployment status
1 parent 901e045 commit d8e22d7

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

templates/cli/lib/commands/deploy.js.twig

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { Updater, SPINNER_ARC, SPINNER_DOTS } = require('../updater');
66
const { paginate } = require('../paginate');
77
const { questionsDeployBuckets, questionsDeployTeams, questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections, questionsConfirmDeployCollections } = require("../questions");
88
const { actionRunner, success, log, error, commandDescriptions } = require("../parser");
9-
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
9+
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
1010
const {
1111
databasesGet,
1212
databasesCreate,
@@ -41,6 +41,7 @@ const {
4141

4242
const STEP_SIZE = 100; // Resources
4343
const POOL_DEBOUNCE = 2000; // Milliseconds
44+
const POOL_MAX_DEBOUNCE = 30; // Times
4445

4546
let poolMaxDebounces = 30;
4647

@@ -312,11 +313,13 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
312313
log('Pushing functions\n');
313314

314315
Updater.start(false,)
316+
let successfullyPushed = 0;
315317
let successfullyDeployed = 0;
316318

317319
await Promise.all(functions.map(async (func) => {
318320
const ignore = func.ignore ? 'appwrite.json' : '.gitignore';
319321
let functionExists = false;
322+
let deploymentCreated = false;
320323

321324
const updaterRow = new Updater({ status: '', resource: func.name, id: func['$id'], end: `Ignoring using: ${ignore}` });
322325

@@ -438,9 +441,9 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
438441
parseOutput: false
439442
})
440443

441-
updaterRow.update({ status: 'Pushed' })
442-
successfullyDeployed++;
443-
444+
updaterRow.update({ status: 'Pushed' });
445+
deploymentCreated = true;
446+
successfullyPushed++;
444447
} catch (e) {
445448
switch (e.code) {
446449
case 'ENOENT':
@@ -450,12 +453,54 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
450453
updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' })
451454
}
452455
}
456+
457+
if (deploymentCreated) {
458+
try {
459+
const deploymentId = response['$id'];
460+
updaterRow.update({ status: 'Deploying', end: 'Checking deployment status...' })
461+
let pool_checks = 0;
462+
463+
while (true) {
464+
if (pool_checks >= POOL_MAX_DEBOUNCE) {
465+
updaterRow.update({ end: 'Deployment takes too long; check the console' })
466+
break;
467+
}
468+
469+
response = await functionsGetDeployment({
470+
functionId: func['$id'],
471+
deploymentId: deploymentId,
472+
parseOutput: false
473+
});
474+
475+
476+
const status = response['status'];
477+
if (status === 'ready') {
478+
updaterRow.update({ status: 'Deployed' });
479+
successfullyDeployed++;
480+
481+
break;
482+
} else if (status === 'failed') {
483+
updaterRow.fail({ errorMessage: 'failed to deploy' });
484+
485+
break;
486+
} else {
487+
updaterRow.update({ status: 'Deploying', end: `current status: ${status}` })
488+
}
489+
490+
pool_checks++;
491+
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
492+
}
493+
} catch (e) {
494+
updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' })
495+
}
496+
}
497+
453498
updaterRow.stopSpinner();
454499
}));
455500

456501
Updater.stop();
457502

458-
success(`Pushed ${successfullyDeployed} functions`);
503+
success(`Pushed ${successfullyPushed} functions with ${successfullyDeployed} successfully deployed`);
459504
}
460505

461506
const createAttribute = async (databaseId, collectionId, attribute) => {

templates/cli/lib/updater.js.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ class Updater {
3939
let end = chalk.yellow(payload.end);
4040

4141
if (status.toLowerCase().trim() === 'pushed') {
42+
start = chalk.greenBright.bold(status);
43+
prefix = chalk.greenBright.bold('✓');
44+
end = '';
45+
} else if (status.toLowerCase().trim() === 'deploying') {
46+
start = chalk.cyanBright.bold(status);
47+
} else if (status.toLowerCase().trim() === 'deployed') {
4248
start = chalk.green.bold(status);
4349
prefix = chalk.green.bold('✓');
4450
end = '';

0 commit comments

Comments
 (0)