Add amount of jobs ahead in the queue

This commit is contained in:
Kuba Orlik 2022-06-17 12:09:59 +02:00
parent b14955346d
commit 34cb00139f
2 changed files with 19 additions and 6 deletions

View File

@ -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
```

View File

@ -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 {