Add amount of jobs ahead in the queue
This commit is contained in:
parent
b14955346d
commit
34cb00139f
@ -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
|
||||
|
||||
```
|
||||
|
19
request.js
19
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user