browsertrix-crawler/main.js
Ilya Kreymer 761ce7067b
behaviors update (#105)
* update to browsertrix-behaviors 0.2.5 to support improved autoscroll
- add evaluateWithCLI() to support evaluate() with 'getEventListeners()' and other devtools command-line api functions, to allow autoscroll behavior to check if it should exit out early
- inject behaviors into interactive loader to allow testing
- fix signal handler if state not inited yet
- dependencies: update puppeteer-cluster to latest, update pywb to 2.6.5
2022-02-20 22:22:19 -08:00

57 lines
1.1 KiB
JavaScript
Executable file

#!/usr/bin/env node
var crawler = null;
var lastSigInt = 0;
let forceTerm = false;
async function handleTerminate() {
if (!crawler || !crawler.crawlState) {
process.exit(0);
}
try {
if (!crawler.crawlState.drainMax) {
console.log("SIGNAL: gracefully finishing current pages...");
crawler.crawlState.setDrain();
} else if ((Date.now() - lastSigInt) > 200) {
console.log("SIGNAL: stopping crawl now...");
await crawler.serializeConfig();
process.exit(0);
}
lastSigInt = Date.now();
} catch (e) {
console.log(e);
}
}
process.on("SIGINT", async () => {
console.log("SIGINT received...");
await handleTerminate();
});
process.on("SIGTERM", async () => {
if (forceTerm) {
console.log("SIGTERM received, exit immediately");
process.exit(1);
}
console.log("SIGTERM received...");
await handleTerminate();
});
process.on("SIGABRT", async () => {
console.log("SIGABRT received, will force immediate exit on SIGTERM");
forceTerm = true;
});
const { Crawler } = require("./crawler");
crawler = new Crawler();
crawler.run();