mirror of
https://github.com/webrecorder/browsertrix-crawler.git
synced 2025-10-19 06:23:16 +00:00
optimize shutdown: if after interrupt signal was received, redis connection is gone, assume crawler is being terminated and exit quickly, (#292)
don't attemtpt to reconnect to redis (assume crawler is also being shutdown)
This commit is contained in:
parent
5c497f4fa4
commit
3c7c7bfbc4
2 changed files with 12 additions and 0 deletions
4
main.js
4
main.js
|
@ -1,8 +1,10 @@
|
|||
#!/usr/bin/env -S node --experimental-global-webcrypto
|
||||
|
||||
import { logger } from "./util/logger.js";
|
||||
import { setExitOnRedisError } from "./util/redis.js";
|
||||
import { Crawler } from "./crawler.js";
|
||||
|
||||
|
||||
var crawler = null;
|
||||
|
||||
var lastSigInt = 0;
|
||||
|
@ -21,6 +23,8 @@ async function handleTerminate(signame) {
|
|||
process.exit(0);
|
||||
}
|
||||
|
||||
setExitOnRedisError(true);
|
||||
|
||||
try {
|
||||
if (!crawler.interrupted) {
|
||||
logger.info("SIGNAL: gracefully finishing current pages...");
|
||||
|
|
|
@ -4,6 +4,7 @@ import { logger } from "./logger.js";
|
|||
const error = console.error;
|
||||
|
||||
let lastLogTime = 0;
|
||||
let exitOnError = false;
|
||||
|
||||
// log only once every 10 seconds
|
||||
const REDIS_ERROR_LOG_INTERVAL_SECS = 10000;
|
||||
|
@ -17,6 +18,9 @@ console.error = function (...args) {
|
|||
let now = Date.now();
|
||||
|
||||
if ((now - lastLogTime) > REDIS_ERROR_LOG_INTERVAL_SECS) {
|
||||
if (lastLogTime && exitOnError) {
|
||||
logger.fatal("Crawl interrupted, redis gone, exiting", {}, "redis");
|
||||
}
|
||||
logger.warn("ioredis error", {error: args[0]}, "redis");
|
||||
lastLogTime = now;
|
||||
}
|
||||
|
@ -30,3 +34,7 @@ export async function initRedis(url) {
|
|||
await redis.connect();
|
||||
return redis;
|
||||
}
|
||||
|
||||
export function setExitOnRedisError() {
|
||||
exitOnError = true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue