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

Commit be5235c

Browse files
authored
Add ability to set function deploy concurrency (#224)
1 parent e66aea8 commit be5235c

File tree

3 files changed

+62
-45
lines changed

3 files changed

+62
-45
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: node_js
22
node_js:
3-
- '8'
3+
- '12'
44
script:
55
- npm run lint
66
- npm test

lib/deploy.js

+60-43
Original file line numberDiff line numberDiff line change
@@ -656,54 +656,71 @@ function deployTrigger(event, funcName, namespace, service, options) {
656656
}
657657

658658
function deploy(functions, runtime, service, options) {
659-
const errors = [];
660-
let counter = 0;
659+
// Concurrents deploys to execute
660+
const deployConcurrency = process.env.DEPLOY_CONCURRENCY || Number.MAX_VALUE;
661+
662+
return new BbPromise((deployResolve, deployReject) => {
663+
const deployQueue = functions.slice();
664+
665+
const deployFunctions = (functionsToDeploy) => new BbPromise((resolve, reject) => {
666+
const errors = [];
667+
let counter = 0;
668+
// Total number of elements to deploy for this iteration
669+
const elements = helpers.getDeployableItemsNumber(functionsToDeploy);
670+
_.each(functionsToDeploy, (description) => {
671+
const opts = _.defaults({}, options, {
672+
hostname: null,
673+
namespace: 'default',
674+
memorySize: null,
675+
force: false,
676+
verbose: false,
677+
log: console.log,
678+
contentType: ('contentType' in description) ? description.contentType : 'text',
679+
labels: description.labels || {},
680+
});
661681

662-
// Total number of elements to deploy
663-
const elements = helpers.getDeployableItemsNumber(functions);
664-
return new BbPromise((resolve, reject) => {
665-
_.each(functions, (description) => {
666-
const opts = _.defaults({}, options, {
667-
hostname: null,
668-
namespace: 'default',
669-
memorySize: null,
670-
force: false,
671-
verbose: false,
672-
log: console.log,
673-
contentType: ('contentType' in description) ? description.contentType : 'text',
674-
labels: description.labels || {},
682+
const ns = description.namespace || opts.namespace;
683+
if (description.handler) {
684+
deployFunction(description, ns, runtime, opts.contentType, opts)
685+
.catch(deploymentErr => errors.push(deploymentErr))
686+
.then((res) => {
687+
if (res.code && res.code !== 200) {
688+
errors.push(res.message);
689+
}
690+
_.each(description.events, event => {
691+
deployTrigger(event, description.id, ns, service, opts)
692+
.catch(triggerErr => errors.push(triggerErr))
693+
.then((tr) => {
694+
if (tr && tr.code && tr.code !== 200) {
695+
errors.push(tr.message);
696+
}
697+
counter++;
698+
helpers.checkFinished(counter, elements, errors, resolve, reject);
699+
});
700+
});
701+
counter++;
702+
helpers.checkFinished(counter, elements, errors, resolve, reject);
703+
});
704+
} else {
705+
counter++;
706+
opts.log(
707+
`Skipping deployment of ${description.id} since it doesn't have a handler`
708+
);
709+
helpers.checkFinished(counter, elements, errors, resolve, reject);
710+
}
675711
});
712+
});
676713

677-
const ns = description.namespace || opts.namespace;
678-
if (description.handler) {
679-
deployFunction(description, ns, runtime, opts.contentType, opts)
680-
.catch(deploymentErr => errors.push(deploymentErr))
681-
.then((res) => {
682-
if (res.code && res.code !== 200) {
683-
errors.push(res.message);
684-
}
685-
_.each(description.events, event => {
686-
deployTrigger(event, description.id, ns, service, opts)
687-
.catch(triggerErr => errors.push(triggerErr))
688-
.then((tr) => {
689-
if (tr && tr.code && tr.code !== 200) {
690-
errors.push(tr.message);
691-
}
692-
counter++;
693-
helpers.checkFinished(counter, elements, errors, resolve, reject);
694-
});
695-
});
696-
counter++;
697-
helpers.checkFinished(counter, elements, errors, resolve, reject);
698-
});
714+
const nextDeploy = () => {
715+
if (deployQueue.length > 0) {
716+
const functionsToDeploy = deployQueue.splice(0, deployConcurrency);
717+
deployFunctions(functionsToDeploy).then(() => nextDeploy()).catch((ex) => deployReject(ex));
699718
} else {
700-
counter++;
701-
opts.log(
702-
`Skipping deployment of ${description.id} since it doesn't have a handler`
703-
);
704-
helpers.checkFinished(counter, elements, errors, resolve, reject);
719+
deployResolve();
705720
}
706-
});
721+
};
722+
723+
nextDeploy();
707724
});
708725
}
709726

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.2",
3+
"version": "0.11.0",
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)