@@ -6,7 +6,7 @@ const { Updater, SPINNER_ARC, SPINNER_DOTS } = require('../updater');
6
6
const { paginate } = require('../paginate');
7
7
const { questionsDeployBuckets, questionsDeployTeams, questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections, questionsConfirmDeployCollections } = require("../questions");
8
8
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');
10
10
const {
11
11
databasesGet,
12
12
databasesCreate,
@@ -41,6 +41,7 @@ const {
41
41
42
42
const STEP_SIZE = 100; // Resources
43
43
const POOL_DEBOUNCE = 2000; // Milliseconds
44
+ const POOL_MAX_DEBOUNCE = 30; // Times
44
45
45
46
let poolMaxDebounces = 30;
46
47
@@ -312,11 +313,13 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
312
313
log('Pushing functions\n');
313
314
314
315
Updater.start(false,)
316
+ let successfullyPushed = 0;
315
317
let successfullyDeployed = 0;
316
318
317
319
await Promise.all(functions.map(async (func) => {
318
320
const ignore = func.ignore ? 'appwrite.json' : '.gitignore';
319
321
let functionExists = false;
322
+ let deploymentCreated = false;
320
323
321
324
const updaterRow = new Updater({ status: '', resource: func.name, id: func['$id'], end: `Ignoring using: ${ignore}` });
322
325
@@ -438,9 +441,9 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
438
441
parseOutput: false
439
442
})
440
443
441
- updaterRow.update({ status: 'Pushed' })
442
- successfullyDeployed++ ;
443
-
444
+ updaterRow.update({ status: 'Pushed' });
445
+ deploymentCreated = true ;
446
+ successfullyPushed++;
444
447
} catch (e) {
445
448
switch (e.code) {
446
449
case 'ENOENT':
@@ -450,12 +453,54 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
450
453
updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' })
451
454
}
452
455
}
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
+
453
498
updaterRow.stopSpinner();
454
499
}));
455
500
456
501
Updater.stop();
457
502
458
- success(`Pushed ${successfullyDeployed } functions`);
503
+ success(`Pushed ${successfullyPushed } functions with ${successfullyDeployed} successfully deployed `);
459
504
}
460
505
461
506
const createAttribute = async (databaseId, collectionId, attribute) => {
0 commit comments