Skip to content

Commit 3868a80

Browse files
committed
refactoring(cli): conventions and messages
1 parent d8e22d7 commit 3868a80

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ const {
4040
} = require("./teams");
4141

4242
const STEP_SIZE = 100; // Resources
43-
const POOL_DEBOUNCE = 2000; // Milliseconds
44-
const POOL_MAX_DEBOUNCE = 30; // Times
43+
const POLL_DEBOUNCE = 2000; // Milliseconds
44+
const POLL_MAX_DEBOUNCE = 30; // Times
4545

46-
let poolMaxDebounces = 30;
46+
let pollMaxDebounces = 30;
4747

4848
const awaitPools = {
4949
wipeAttributes: async (databaseId, collectionId, iteration = 1) => {
50-
if (iteration > poolMaxDebounces) {
50+
if (iteration > pollMaxDebounces) {
5151
return false;
5252
}
5353

@@ -64,12 +64,12 @@ const awaitPools = {
6464

6565
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
6666
if (steps > 1 && iteration === 1) {
67-
poolMaxDebounces *= steps;
67+
pollMaxDebounces *= steps;
6868

69-
log('Found a large number of attributes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
69+
log('Found a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
7070
}
7171

72-
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
72+
await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
7373

7474
return await awaitPools.wipeAttributes(
7575
databaseId,
@@ -78,7 +78,7 @@ const awaitPools = {
7878
);
7979
},
8080
wipeIndexes: async (databaseId, collectionId, iteration = 1) => {
81-
if (iteration > poolMaxDebounces) {
81+
if (iteration > pollMaxDebounces) {
8282
return false;
8383
}
8484

@@ -95,12 +95,12 @@ const awaitPools = {
9595

9696
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
9797
if (steps > 1 && iteration === 1) {
98-
poolMaxDebounces *= steps;
98+
pollMaxDebounces *= steps;
9999

100-
log('Found a large number of indexes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
100+
log('Found a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
101101
}
102102

103-
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
103+
await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
104104

105105
return await awaitPools.wipeIndexes(
106106
databaseId,
@@ -109,7 +109,7 @@ const awaitPools = {
109109
);
110110
},
111111
wipeVariables: async (functionId, iteration = 1) => {
112-
if (iteration > poolMaxDebounces) {
112+
if (iteration > pollMaxDebounces) {
113113
return false;
114114
}
115115

@@ -125,28 +125,28 @@ const awaitPools = {
125125

126126
let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
127127
if (steps > 1 && iteration === 1) {
128-
poolMaxDebounces *= steps;
128+
pollMaxDebounces *= steps;
129129

130-
log('Found a large number of variables, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
130+
log('Found a large number of variables, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
131131
}
132132

133-
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
133+
await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
134134

135135
return await awaitPools.wipeVariables(
136136
functionId,
137137
iteration + 1
138138
);
139139
},
140140
expectAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => {
141-
if (iteration > poolMaxDebounces) {
141+
if (iteration > pollMaxDebounces) {
142142
return false;
143143
}
144144

145145
let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE));
146146
if (steps > 1 && iteration === 1) {
147-
poolMaxDebounces *= steps;
147+
pollMaxDebounces *= steps;
148148

149-
log('Creating a large number of attributes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
149+
log('Creating a large number of attributes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
150150
}
151151

152152
const { attributes } = await paginate(databasesListAttributes, {
@@ -173,7 +173,7 @@ const awaitPools = {
173173
return true;
174174
}
175175

176-
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
176+
await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
177177

178178
return await awaitPools.expectAttributes(
179179
databaseId,
@@ -183,15 +183,15 @@ const awaitPools = {
183183
);
184184
},
185185
expectIndexes: async (databaseId, collectionId, indexKeys, iteration = 1) => {
186-
if (iteration > poolMaxDebounces) {
186+
if (iteration > pollMaxDebounces) {
187187
return false;
188188
}
189189

190190
let steps = Math.max(1, Math.ceil(indexKeys.length / STEP_SIZE));
191191
if (steps > 1 && iteration === 1) {
192-
poolMaxDebounces *= steps;
192+
pollMaxDebounces *= steps;
193193

194-
log('Creating a large number of indexes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
194+
log('Creating a large number of indexes, increasing timeout to ' + (pollMaxDebounces * POLL_DEBOUNCE / 1000 / 60) + ' minutes')
195195
}
196196

197197
const { indexes } = await paginate(databasesListIndexes, {
@@ -218,7 +218,7 @@ const awaitPools = {
218218
return true;
219219
}
220220

221-
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
221+
await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
222222

223223
return await awaitPools.expectIndexes(
224224
databaseId,
@@ -458,11 +458,11 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
458458
try {
459459
const deploymentId = response['$id'];
460460
updaterRow.update({ status: 'Deploying', end: 'Checking deployment status...' })
461-
let pool_checks = 0;
461+
let pollChecks = 0;
462462

463463
while (true) {
464-
if (pool_checks >= POOL_MAX_DEBOUNCE) {
465-
updaterRow.update({ end: 'Deployment takes too long; check the console' })
464+
if (pollChecks >= POLL_MAX_DEBOUNCE) {
465+
updaterRow.update({ end: 'Deployment is taking too long. Please check the console for more details.' })
466466
break;
467467
}
468468

@@ -480,18 +480,18 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
480480

481481
break;
482482
} else if (status === 'failed') {
483-
updaterRow.fail({ errorMessage: 'failed to deploy' });
483+
updaterRow.fail({ errorMessage: 'Failed to deploy.' });
484484

485485
break;
486486
} else {
487-
updaterRow.update({ status: 'Deploying', end: `current status: ${status}` })
487+
updaterRow.update({ status: 'Deploying', end: `Current status: ${status}` })
488488
}
489489

490-
pool_checks++;
491-
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
490+
pollChecks++;
491+
await new Promise(resolve => setTimeout(resolve, POLL_DEBOUNCE));
492492
}
493493
} catch (e) {
494-
updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' })
494+
updaterRow.fail({ errorMessage: e.message ?? 'Unknown error occurred. Please try again' })
495495
}
496496
}
497497

0 commit comments

Comments
 (0)