Skip to content

Commit 12428be

Browse files
committed
Add linear timeout for awaiters
1 parent 0ff8df5 commit 12428be

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

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

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ const {
3737
teamsCreate
3838
} = require("./teams");
3939

40-
const POOL_DEBOUNCE = 2000; // in milliseconds
41-
const POOL_MAX_DEBOUNCES = 30;
40+
const STEP_SIZE = 100; // Resources
41+
const POOL_DEBOUNCE = 2000; // Milliseconds
42+
43+
let poolMaxDebounces = 30;
4244

4345
const awaitPools = {
4446
wipeAttributes: async (databaseId, collectionId, iteration = 1) => {
45-
if (iteration > POOL_MAX_DEBOUNCES) {
47+
if (iteration > poolMaxDebounces) {
4648
return false;
4749
}
4850

@@ -58,11 +60,18 @@ const awaitPools = {
5860
return true;
5961
}
6062

63+
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
64+
if (steps > 1 && iteration === 1) {
65+
poolMaxDebounces *= steps;
66+
67+
log('Found a large number of attributes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
68+
}
69+
6170
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
6271
return await awaitPools.wipeAttributes(databaseId, collectionId, iteration + 1);
6372
},
6473
wipeIndexes: async (databaseId, collectionId, iteration = 1) => {
65-
if (iteration > POOL_MAX_DEBOUNCES) {
74+
if (iteration > poolMaxDebounces) {
6675
return false;
6776
}
6877

@@ -78,16 +87,31 @@ const awaitPools = {
7887
return true;
7988
}
8089

90+
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
91+
if (steps > 1 && iteration === 1) {
92+
poolMaxDebounces *= steps;
93+
94+
log('Found a large number of indexes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
95+
}
96+
8197
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
8298
return await awaitPools.wipeIndexes(databaseId, collectionId, iteration + 1);
8399
},
84100
expectAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => {
85-
if (iteration > POOL_MAX_DEBOUNCES) {
101+
if (iteration > poolMaxDebounces) {
86102
return false;
87103
}
88104

89105
// TODO: Pagination?
90106
const { attributes: remoteAttributes } = await databasesListAttributes({
107+
let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE));
108+
if (steps > 1 && iteration === 1) {
109+
poolMaxDebounces *= steps;
110+
111+
log('Creating a large number of attributes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
112+
}
113+
114+
const { attributes } = await paginate(databasesListAttributes, {
91115
databaseId,
92116
collectionId,
93117
queries: ['limit(100)'],
@@ -114,12 +138,19 @@ const awaitPools = {
114138
return await awaitPools.expectAttributes(databaseId, collectionId, attributeKeys, iteration + 1);
115139
},
116140
expectIndexes: async (databaseId, collectionId, indexKeys, iteration = 1) => {
117-
if (iteration > POOL_MAX_DEBOUNCES) {
141+
if (iteration > poolMaxDebounces) {
118142
return false;
119143
}
120144

121145
// TODO: Pagination?
122146
const { indexes: remoteIndexes } = await databasesListIndexes({
147+
let steps = Math.max(1, Math.ceil(indexKeys.length / STEP_SIZE));
148+
if (steps > 1 && iteration === 1) {
149+
poolMaxDebounces *= steps;
150+
151+
log('Creating a large number of indexes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
152+
}
153+
123154
databaseId,
124155
collectionId,
125156
queries: ['limit(100)'],

0 commit comments

Comments
 (0)