From d723f95cb95171e72b436cd67c02fb38a5a25be3 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Thu, 17 Mar 2022 08:58:13 +0000 Subject: [PATCH] add missing lock.js update chrome launch flag --- crawler.js | 2 +- util/lock.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 util/lock.js diff --git a/crawler.js b/crawler.js index aaf0b84a..f4fedf25 100644 --- a/crawler.js +++ b/crawler.js @@ -259,7 +259,7 @@ class Crawler { "--no-sandbox", "--disable-background-media-suspend", "--autoplay-policy=no-user-gesture-required", - "--disable-features=IsolateOrigins,site-per-process", + "--disable-features=Translate,LazyFrameLoading,IsolateOrigins,site-per-process", "--disable-popup-blocking", "--disable-backgrounding-occluded-windows", ]; diff --git a/util/lock.js b/util/lock.js new file mode 100644 index 00000000..3e5ab807 --- /dev/null +++ b/util/lock.js @@ -0,0 +1,37 @@ +const path = require("path"); +const fs = require("fs"); +const os = require("os"); + +class Lock +{ + constructor(dir) { + this.lockDir = path.join(dir, ".lock"); + this.lockFile = path.join(this.lockDir, "." + os.hostname()); + fs.mkdirSync(this.lockDir, {recursive: true}); + fs.closeSync(fs.openSync(this.lockFile, "a")); + console.log(`Created lock file ${this.lockFile}`); + } + + release() { + try { + fs.unlinkSync(this.lockFile); + console.log(`Removed lock file ${this.lockFile}`); + } catch (e) { + // ignore remove failure, but see if other locks exist + } + + try { + fs.rmdirSync(this.lockDir); + } catch (e) { + // true if no such dir, otherwise not released + return (e.code === "ENOENT"); + } + + console.log("No more locks"); + return true; + } +} + + + +module.exports.Lock = Lock;