Skip to content

Commit 33a4351

Browse files
committed
fix(cli): fix deploy function
remoteVariables was undefined so use total instead and make it match how it's done for wiping attributes and indexes.
1 parent 8d93209 commit 33a4351

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,35 @@ const awaitPools = {
106106
iteration + 1
107107
);
108108
},
109+
wipeVariables: async (functionId, iteration = 1) => {
110+
if (iteration > poolMaxDebounces) {
111+
return false;
112+
}
113+
114+
const { total } = await functionsListVariables({
115+
functionId,
116+
queries: ['limit(1)'],
117+
parseOutput: false
118+
});
119+
120+
if (total === 0) {
121+
return true;
122+
}
123+
124+
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
125+
if (steps > 1 && iteration === 1) {
126+
poolMaxDebounces *= steps;
127+
128+
log('Found a large number of variables, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
129+
}
130+
131+
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
132+
133+
return await awaitPools.wipeVariables(
134+
functionId,
135+
iteration + 1
136+
);
137+
},
109138
expectAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => {
110139
if (iteration > poolMaxDebounces) {
111140
return false;
@@ -310,7 +339,7 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
310339

311340
if (total === 0) {
312341
deployVariables = true;
313-
} else if (remoteVariables.length > 0 && !yes) {
342+
} else if (total > 0 && !yes) {
314343
const variableAnswers = await inquirer.prompt(questionsDeployFunctions[1])
315344
deployVariables = variableAnswers.override.toLowerCase() === "yes";
316345
}
@@ -320,13 +349,23 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
320349
} else {
321350
log(`Deploying variables for ${func.name} ( ${func['$id']} )`);
322351

323-
await Promise.all(remoteVariables.map(async remoteVariable => {
352+
const { variables } = await paginate(functionsListVariables, {
353+
functionId: func['$id'],
354+
parseOutput: false
355+
}, 100, 'variables');
356+
357+
await Promise.all(variables.map(async variable => {
324358
await functionsDeleteVariable({
325359
functionId: func['$id'],
326-
variableId: remoteVariable['$id'],
360+
variableId: variable['$id'],
327361
parseOutput: false
328362
});
329363
}));
364+
365+
let result = await awaitPools.wipeVariables(func['$id']);
366+
if (!result) {
367+
throw new Error("Variable deletion timed out.");
368+
}
330369

331370
// Deploy local variables
332371
await Promise.all(Object.keys(func.variables).map(async localVariableKey => {

0 commit comments

Comments
 (0)