Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit b916fac

Browse files
authored
New waitForDeployment check logic (#215)
* exponential and (very) longer waitForDeployment interval * Bump version * setExponentialInterval fix (timer cancelation not working for synchronous callback) * variable name refactoring in setExponentialInterval
1 parent 5d92e2e commit b916fac

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

lib/deploy.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ function waitForDeployment(funcName, requestMoment, namespace, options) {
211211
let successfulCount = 0;
212212
let previousPodStatus = '';
213213
return new BbPromise((resolve, reject) => {
214-
const loop = setInterval(() => {
215-
if (retries > 10) {
214+
const loop = helpers.setExponentialInterval(() => {
215+
if (retries > 30) {
216216
opts.log(
217217
`Giving up, unable to retrieve the status of the ${funcName} deployment. `
218218
);
219-
clearInterval(loop);
219+
loop.clearInterval();
220220
reject(`Unable to retrieve the status of the ${funcName} deployment`);
221221
}
222222
let runningPods = 0;
@@ -249,7 +249,7 @@ function waitForDeployment(funcName, requestMoment, namespace, options) {
249249
} else if (pod.status.containerStatuses[0].restartCount > 2) {
250250
opts.log('ERROR: Failed to deploy the function');
251251
process.exitCode = process.exitCode || 1;
252-
clearInterval(loop);
252+
loop.clearInterval();
253253
}
254254
}
255255
});
@@ -281,7 +281,7 @@ function waitForDeployment(funcName, requestMoment, namespace, options) {
281281
opts.log(`Unable to find internal service for ${funcName}. Retrying...`);
282282
} else {
283283
opts.log(`Function ${funcName} successfully deployed`);
284-
clearInterval(loop);
284+
loop.clearInterval();
285285
resolve();
286286
}
287287
}
@@ -304,7 +304,7 @@ function waitForDeployment(funcName, requestMoment, namespace, options) {
304304
}
305305
}
306306
});
307-
}, 2000);
307+
}, 2000, 30000);
308308
});
309309
}
310310

lib/helpers.js

+27
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,32 @@ function getDeployableItemsNumber(functions) {
241241
return _.sum([_.keys(functions).length].concat(_.map(functions, f => _.size(f.events))));
242242
}
243243

244+
function setExponentialInterval(targetFunction, initialDelay, maxDelay) {
245+
let delay = initialDelay;
246+
let timer;
247+
const timerWrapper = () => {
248+
try {
249+
targetFunction();
250+
} catch (ex) {
251+
console.error(ex);
252+
}
253+
if (timer) {
254+
delay = Math.round(delay * 1.2);
255+
if (delay > maxDelay) {
256+
delay = maxDelay;
257+
}
258+
timer = setTimeout(timerWrapper, delay);
259+
}
260+
};
261+
timer = setTimeout(timerWrapper, delay);
262+
return {
263+
clearInterval: () => {
264+
clearTimeout(timer);
265+
timer = null;
266+
},
267+
};
268+
}
269+
244270
module.exports = {
245271
warnUnsupportedOptions,
246272
loadKubeConfig,
@@ -250,4 +276,5 @@ module.exports = {
250276
getRuntimeDepfile,
251277
checkFinished,
252278
getDeployableItemsNumber,
279+
setExponentialInterval,
253280
};

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-kubeless",
3-
"version": "0.10.1",
3+
"version": "0.10.2",
44
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)