Primeiro commit do projeto Angular
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
import type { PiscinaTask } from '../../task_queue';
|
||||
import type { PiscinaWorker } from '..';
|
||||
export type PiscinaLoadBalancer = (task: PiscinaTask, workers: PiscinaWorker[]) => PiscinaWorker | null;
|
||||
export type LeastBusyBalancerOptions = {
|
||||
maximumUsage: number;
|
||||
};
|
||||
export declare function LeastBusyBalancer(opts: LeastBusyBalancerOptions): PiscinaLoadBalancer;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LeastBusyBalancer = LeastBusyBalancer;
|
||||
function LeastBusyBalancer(opts) {
|
||||
const { maximumUsage } = opts;
|
||||
return (task, workers) => {
|
||||
let candidate = null;
|
||||
let checkpoint = maximumUsage;
|
||||
for (const worker of workers) {
|
||||
if (worker.currentUsage === 0) {
|
||||
candidate = worker;
|
||||
break;
|
||||
}
|
||||
if (worker.isRunningAbortableTask)
|
||||
continue;
|
||||
if (task.isAbortable === false &&
|
||||
(worker.currentUsage < checkpoint)) {
|
||||
candidate = worker;
|
||||
checkpoint = worker.currentUsage;
|
||||
}
|
||||
}
|
||||
return candidate;
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/worker_pool/balancer/index.ts"],"names":[],"mappings":";;AAWA,8CA2BC;AA3BD,SAAgB,iBAAiB,CAC/B,IAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAE9B,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;QACvB,IAAI,SAAS,GAAyB,IAAI,CAAC;QAC3C,IAAI,UAAU,GAAG,YAAY,CAAC;QAC9B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;gBAC9B,SAAS,GAAG,MAAM,CAAC;gBACnB,MAAM;YACR,CAAC;YAED,IAAI,MAAM,CAAC,sBAAsB;gBAAE,SAAS;YAE5C,IACE,IAAI,CAAC,WAAW,KAAK,KAAK;gBAC1B,CAAC,MAAM,CAAC,YAAY,GAAG,UAAU,CAAC,EAClC,CAAC;gBACD,SAAS,GAAG,MAAM,CAAC;gBACnB,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC;YACnC,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC"}
|
||||
Reference in New Issue
Block a user