aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-01-18 18:26:31 -0500
committerHolden Rohrer <hr@hrhr.dev>2020-01-18 18:26:31 -0500
commit338b8ca37f9552a9e00a77bfa2c7ad5d6b222b26 (patch)
treea90d35c544628a422d09b8866d090f9b5bc3842c
parent779ad8a69c031b768d16af79154a30e92730e5c3 (diff)
Schedule bugfix
It was adding too many prios to prios[] for the number of available jobs[] queues because they were added on every job insertion instead of on every new queue creation
-rw-r--r--tools/schedule.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/schedule.js b/tools/schedule.js
index 033fddb..fabcce7 100644
--- a/tools/schedule.js
+++ b/tools/schedule.js
@@ -28,9 +28,11 @@ exports.Queue = function(delayms, maxExport, call){
this.enqueue = function(job){
if (! (job instanceof exports.Job)) job = new exports.Job(job);
let prio = job.prio;
- if (!jobs[prio]) jobs[prio] = [];
+ if (!jobs[prio]){
+ jobs[prio] = [];
+ prios.splice(0, Math.abs(bs(prios, prio, (el, ne) => el-ne)), prio); // prios is meant to be sorted least to most, and each job layer is too (by "maximum number of rounds").
+ }
jobs[prio].splice(0, Math.abs(bs(jobs[prio], job, (el, ne) => el.maxr() - ne.maxr())), job);
- prios.splice(0, Math.abs(bs(prios, prio, (el, ne) => el-ne)), prio); // prios is meant to be sorted least to most, and each job layer is too (by "maximum number of rounds").
// These were sorted like this so that getNumOrAll could use [0] or [.length-1] or .pop instead of having to re-sort lists repetitively.
if (open) dequeue();
}