@andersbakken/fisk 3.5.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -564,7 +564,22 @@ let jobQueue = [];
564
564
 
565
565
  server.on("headers", (headers, req) => {
566
566
  // console.log("request is", req.headers);
567
- let wait = (jobQueue.length >= client.slots || (objectCache && objectCache.state(req.headers["x-fisk-sha1"]) == "exists"));
567
+ let wait = false;
568
+ if (objectCache && objectCache.state(req.headers["x-fisk-sha1"]) == "exists") {
569
+ wait = true;
570
+ } else if (jobQueue.length >= client.slots) {
571
+ const priority = parseInt(req.headers["x-fisk-sha1"]) || 0;
572
+ let idx = jobQueue.length - 1;
573
+ while (idx >= client.slots) {
574
+ let job = jobQueue[idx].job;
575
+ if (job.priority >= priority) {
576
+ break;
577
+ }
578
+ --idx;
579
+ }
580
+
581
+ wait = idx >= client.slots;
582
+ }
568
583
  headers.push(`x-fisk-wait: ${wait}`);
569
584
  });
570
585
 
@@ -645,7 +660,7 @@ server.on("job", job => {
645
660
  let uploadDuration;
646
661
 
647
662
  // console.log("sending to server");
648
- var j = {
663
+ const j = {
649
664
  id: job.id,
650
665
  job: job,
651
666
  op: undefined,
@@ -840,7 +855,17 @@ server.on("job", job => {
840
855
  }
841
856
  });
842
857
 
843
- jobQueue.push(j);
858
+ let idx = jobQueue.length;
859
+ while (idx > 0) {
860
+ const jobJob = jobQueue[idx - 1].job;
861
+ if (jobJob.priority >= job.priority) {
862
+ // console.log("Stopping at idx", idx, "Because of", job.priority, jobJob.priority, client.slots, jobJob.length);
863
+ break;
864
+ }
865
+ --idx;
866
+ }
867
+ jobQueue.splice(idx, 0, j);
868
+
844
869
  if (jobQueue.length <= client.slots) {
845
870
  // console.log(`starting j ${j.id} because ${jobQueue.length} ${client.slots}`);
846
871
  j.start();
package/builder/server.js CHANGED
@@ -123,6 +123,7 @@ class Server extends EventEmitter {
123
123
  hostname: req.headers["x-fisk-client-hostname"],
124
124
  user: req.headers["x-fisk-user"],
125
125
  sourceFile: req.headers["x-fisk-sourcefile"],
126
+ priority: parseInt(req.headers["x-fisk-priority"]) || 0,
126
127
  sha1: req.headers["x-fisk-sha1"],
127
128
  id: parseInt(req.headers["x-fisk-job-id"]),
128
129
  builderIp: req.headers["x-fisk-builder-ip"] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andersbakken/fisk",
3
- "version": "3.5.0",
3
+ "version": "3.5.1",
4
4
  "description": "Fisk, a distributed compile system",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"