2020-09-19 17:36:02 +02:00
|
|
|
const os = require('os');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum number of concurrent tasks we want to have on some CLI and CI tasks.
|
2020-11-03 21:27:10 +01:00
|
|
|
* The amount of CPUS minus one, arbitrary limited to 15 to not overload CI executors.
|
2020-09-19 17:36:02 +02:00
|
|
|
* @type {number}
|
|
|
|
*/
|
2020-11-03 21:27:10 +01:00
|
|
|
const maxConcurrentTasks = Math.min(Math.max(1, os.cpus().length - 1), 15);
|
2020-09-19 17:36:02 +02:00
|
|
|
|
2020-09-19 19:17:43 +02:00
|
|
|
/**
|
|
|
|
* Use a simple round robin to filter input data according to the CI node currently running the script
|
|
|
|
* @param {Array} arrayOfData An array of anything you want
|
|
|
|
* @returns {Array} An array containing only the data that shoud be used by current CI node.
|
|
|
|
*/
|
|
|
|
function filterDataForCurrentCircleCINode(arrayOfData) {
|
|
|
|
const nodeIndex = +process.env.CIRCLE_NODE_INDEX || 0;
|
|
|
|
const numberOfNodes = +process.env.CIRCLE_NODE_TOTAL || 1;
|
|
|
|
|
|
|
|
return arrayOfData.filter((_, index) => {
|
|
|
|
return index % numberOfNodes === nodeIndex;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-19 17:36:02 +02:00
|
|
|
module.exports = {
|
|
|
|
maxConcurrentTasks,
|
2020-09-19 19:17:43 +02:00
|
|
|
filterDataForCurrentCircleCINode,
|
2020-09-19 17:36:02 +02:00
|
|
|
};
|