Skip to content

Commit dcee08a

Browse files
committed
feat(cli): Custom debounce limit
1 parent 16142d8 commit dcee08a

File tree

1 file changed

+47
-29
lines changed

1 file changed

+47
-29
lines changed

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

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ const { checkDeployConditions } = require('../utils');
6868
const STEP_SIZE = 100; // Resources
6969
const POLL_DEBOUNCE = 2000; // Milliseconds
7070
const POLL_MAX_DEBOUNCE = 1800; // Times of POLL_DEBOUNCE (1 hour)
71+
const POLL_DEFAULT_VALUE = 30;
7172

72-
let pollMaxDebounces = 30;
73+
let pollMaxDebounces = POLL_DEFAULT_VALUE;
7374

7475
const changeableKeys = ['status', 'required', 'xdefault', 'elements', 'min', 'max', 'default', 'error'];
7576

@@ -90,11 +91,13 @@ const awaitPools = {
9091
return true;
9192
}
9293

93-
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
94-
if (steps > 1 && iteration === 1) {
95-
pollMaxDebounces *= steps;
94+
if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
95+
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
96+
if (steps > 1 && iteration === 1) {
97+
pollMaxDebounces *= steps;
9698

97-
log('Found a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
99+
log('Found a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
100+
}
98101
}
99102

100103
await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
@@ -121,11 +124,13 @@ const awaitPools = {
121124
return true;
122125
}
123126

124-
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
125-
if (steps > 1 && iteration === 1) {
126-
pollMaxDebounces *= steps;
127+
if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
128+
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
129+
if (steps > 1 && iteration === 1) {
130+
pollMaxDebounces *= steps;
127131

128-
log('Found a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
132+
log('Found a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
133+
}
129134
}
130135

131136
await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
@@ -151,11 +156,13 @@ const awaitPools = {
151156
return true;
152157
}
153158

154-
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
155-
if (steps > 1 && iteration === 1) {
156-
pollMaxDebounces *= steps;
159+
if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
160+
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
161+
if (steps > 1 && iteration === 1) {
162+
pollMaxDebounces *= steps;
157163

158-
log('Found a large number of variables, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
164+
log('Found a large number of variables, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
165+
}
159166
}
160167

161168
await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
@@ -170,11 +177,13 @@ const awaitPools = {
170177
return false;
171178
}
172179

173-
let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE));
174-
if (steps > 1 && iteration === 1) {
175-
pollMaxDebounces *= steps;
180+
if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
181+
let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE));
182+
if (steps > 1 && iteration === 1) {
183+
pollMaxDebounces *= steps;
176184

177-
log('Found a large number of attributes to be deleted. Increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
185+
log('Found a large number of attributes to be deleted. Increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
186+
}
178187
}
179188

180189
const { attributes } = await paginate(databasesListAttributes, {
@@ -203,11 +212,13 @@ const awaitPools = {
203212
return false;
204213
}
205214

206-
let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE));
207-
if (steps > 1 && iteration === 1) {
208-
pollMaxDebounces *= steps;
215+
if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
216+
let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE));
217+
if (steps > 1 && iteration === 1) {
218+
pollMaxDebounces *= steps;
209219

210-
log('Creating a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
220+
log('Creating a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
221+
}
211222
}
212223

213224
const { attributes } = await paginate(databasesListAttributes, {
@@ -248,11 +259,13 @@ const awaitPools = {
248259
return false;
249260
}
250261

251-
let steps = Math.max(1, Math.ceil(indexKeys.length / STEP_SIZE));
252-
if (steps > 1 && iteration === 1) {
253-
pollMaxDebounces *= steps;
262+
if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
263+
let steps = Math.max(1, Math.ceil(indexKeys.length / STEP_SIZE));
264+
if (steps > 1 && iteration === 1) {
265+
pollMaxDebounces *= steps;
254266

255-
log('Creating a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
267+
log('Creating a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
268+
}
256269
}
257270

258271
const { indexes } = await paginate(databasesListIndexes, {
@@ -648,7 +661,7 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection)
648661

649662
if (changes.length > 0) {
650663
changedAttributes = changes.map((change) => change.attribute);
651-
await Promise.all(changedAttributes.map((changed) => updateAttribute(collection['databaseId'],collection['$id'], changed)));
664+
await Promise.all(changedAttributes.map((changed) => updateAttribute(collection['databaseId'], collection['$id'], changed)));
652665
}
653666

654667
const deletingAttributes = deleting.map((change) => change.attribute);
@@ -1024,9 +1037,9 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero
10241037
});
10251038

10261039
if (!async) {
1027-
if(successfullyPushed === 0) {
1040+
if (successfullyPushed === 0) {
10281041
error('No functions were pushed.');
1029-
} else if(successfullyDeployed != successfullyPushed) {
1042+
} else if (successfullyDeployed != successfullyPushed) {
10301043
warn(`Successfully pushed ${successfullyDeployed} of ${successfullyPushed} functions`)
10311044
} else {
10321045
success(`Successfully pushed ${successfullyPushed} functions.`);
@@ -1036,9 +1049,13 @@ const pushFunction = async ({ functionId, async, returnOnZero } = { returnOnZero
10361049
}
10371050
}
10381051

1039-
const pushCollection = async ({ returnOnZero } = { returnOnZero: false }) => {
1052+
const pushCollection = async ({ returnOnZero, debounce } = { returnOnZero: false }) => {
10401053
const collections = [];
10411054

1055+
if (debounce) {
1056+
pollMaxDebounces = debounce;
1057+
}
1058+
10421059
if (cliConfig.all) {
10431060
checkDeployConditions(localConfig);
10441061
if (localConfig.getCollections().length === 0) {
@@ -1410,6 +1427,7 @@ push
14101427
.command("collection")
14111428
.alias("collections")
14121429
.description("Push collections in the current project.")
1430+
.option(`-d, --debounce <maxDebounces>`, `Max number of debounces, default: 30.`)
14131431
.action(actionRunner(pushCollection));
14141432

14151433
push

0 commit comments

Comments
 (0)