@@ -106,6 +106,35 @@ const awaitPools = {
106
106
iteration + 1
107
107
);
108
108
},
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
+ },
109
138
expectAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => {
110
139
if (iteration > poolMaxDebounces) {
111
140
return false;
@@ -310,7 +339,7 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
310
339
311
340
if (total === 0) {
312
341
deployVariables = true;
313
- } else if (remoteVariables.length > 0 && !yes) {
342
+ } else if (total > 0 && !yes) {
314
343
const variableAnswers = await inquirer.prompt(questionsDeployFunctions[1])
315
344
deployVariables = variableAnswers.override.toLowerCase() === "yes";
316
345
}
@@ -320,13 +349,23 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
320
349
} else {
321
350
log(`Deploying variables for ${func.name} ( ${func['$id']} )`);
322
351
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 => {
324
358
await functionsDeleteVariable({
325
359
functionId: func['$id'],
326
- variableId: remoteVariable ['$id'],
360
+ variableId: variable ['$id'],
327
361
parseOutput: false
328
362
});
329
363
}));
364
+
365
+ let result = await awaitPools.wipeVariables(func['$id']);
366
+ if (!result) {
367
+ throw new Error("Variable deletion timed out.");
368
+ }
330
369
331
370
// Deploy local variables
332
371
await Promise.all(Object.keys(func.variables).map(async localVariableKey => {
0 commit comments