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
|
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
|
## Running the server
|
||||||
|
|
||||||
```
|
```
|
||||||
|
19
request.js
19
request.js
@ -5,6 +5,8 @@ const { v4: uuid } = require("uuid");
|
|||||||
const { spawn } = require("child_process");
|
const { spawn } = require("child_process");
|
||||||
const containerPool = require("./container-pool");
|
const containerPool = require("./container-pool");
|
||||||
|
|
||||||
|
let queue_order = [];
|
||||||
|
|
||||||
module.exports = class ScreenshotRequest {
|
module.exports = class ScreenshotRequest {
|
||||||
constructor(url, domains) {
|
constructor(url, domains) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
@ -22,12 +24,28 @@ module.exports = class ScreenshotRequest {
|
|||||||
return this.exec();
|
return this.exec();
|
||||||
});
|
});
|
||||||
requests[this.id] = this;
|
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() {
|
async getJSON() {
|
||||||
return {
|
return {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
domains: this.domains,
|
domains: this.domains,
|
||||||
|
jobs_ahead: this.getJobsAhead(),
|
||||||
id: this.id,
|
id: this.id,
|
||||||
status: this.status,
|
status: this.status,
|
||||||
output: this.output,
|
output: this.output,
|
||||||
@ -75,6 +93,7 @@ module.exports = class ScreenshotRequest {
|
|||||||
this.process.on("close", (exitCode) => {
|
this.process.on("close", (exitCode) => {
|
||||||
this.setFinished();
|
this.setFinished();
|
||||||
container.close();
|
container.close();
|
||||||
|
queue_order = queue_order.filter((request) => request != this);
|
||||||
if (exitCode === 0) {
|
if (exitCode === 0) {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user