From 34cb00139f04bb512583d3c9033127d509d3b05d Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Fri, 17 Jun 2022 12:09:59 +0200 Subject: [PATCH] Add amount of jobs ahead in the queue --- README.md | 6 ------ request.js | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 003d443..3f86eb4 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,6 @@ docker image build -t headless-fox Docker ``` -## Running a single analysis - -``` -BASE_URL=http://localhost:3000 docker run -i -v $PWD/static:/opt/static headless-fox ./script3.sh '{"url": "pearson.pl", "third_party_domains": ["hotjar.com", "cookielaw.org"]}' 123 -``` - ## Running the server ``` diff --git a/request.js b/request.js index a5ee4d7..4f1ee83 100644 --- a/request.js +++ b/request.js @@ -5,6 +5,8 @@ const { v4: uuid } = require("uuid"); const { spawn } = require("child_process"); const containerPool = require("./container-pool"); +let queue_order = []; + module.exports = class ScreenshotRequest { constructor(url, domains) { this.url = url; @@ -22,12 +24,28 @@ module.exports = class ScreenshotRequest { return this.exec(); }); requests[this.id] = this; + queue_order.push(this); + } + + getJobsAhead() { + if (this.status != "waiting") { + return 0; + } + let count = 0; + for (const request of queue_order) { + if (request == this) { + break; + } + count++; + } + return count; } async getJSON() { return { url: this.url, domains: this.domains, + jobs_ahead: this.getJobsAhead(), id: this.id, status: this.status, output: this.output, @@ -75,6 +93,7 @@ module.exports = class ScreenshotRequest { this.process.on("close", (exitCode) => { this.setFinished(); container.close(); + queue_order = queue_order.filter((request) => request != this); if (exitCode === 0) { resolve(); } else {