From b35e8a78d99ba968be6169ab8c34f6062d5d6321 Mon Sep 17 00:00:00 2001 From: Fmstrat Date: Thu, 4 Feb 2021 08:39:26 -0500 Subject: [PATCH 1/3] feat: add restart time for leaking Chromium in Ubuntu --- dotenv-example | 1 + src/config.ts | 3 +++ src/index.ts | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/dotenv-example b/dotenv-example index e528f0495f..c42979c37d 100644 --- a/dotenv-example +++ b/dotenv-example @@ -88,6 +88,7 @@ PUSHOVER_RETRY= PUSHOVER_TOKEN= PUSHOVER_USER= PUSHOVER_PRIORITY= +RESTART_TIME= SCREENSHOT= SHOW_ONLY_BRANDS= SHOW_ONLY_MODELS= diff --git a/src/config.ts b/src/config.ts index 48c0fb1d31..be08e20c90 100644 --- a/src/config.ts +++ b/src/config.ts @@ -434,6 +434,8 @@ const store = { }), }; +const restartTime = envOrNumber(process.env.RESTART_TIME, 0); + export const defaultStoreData = { maxPageSleep: browser.maxSleep, minPageSleep: browser.minSleep, @@ -448,6 +450,7 @@ export const config = { page, proxy, store, + restartTime }; export function setConfig(newConfig: any) { diff --git a/src/index.ts b/src/index.ts index 9ea71ccbd4..fa41c6f516 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,21 @@ puppeteer.use(stealthPlugin()); let browser: Browser | undefined; +async function sleep(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + +/** + * Schedules a restart of the bot + */ +async function restartMain() { + if (config.restartTime > 0) { + await sleep(config.restartTime); + await stop(); + loopMain(); + } +} + /** * Starts the bot. */ @@ -87,11 +102,13 @@ async function stopAndExit() { Process.exit(0); } + /** * Will continually run until user interferes. */ async function loopMain() { try { + restartMain(); await main(); } catch (error: unknown) { logger.error( From 23b426d7f0dd7ba8cb2d29d86d5545a2ece092f2 Mon Sep 17 00:00:00 2001 From: Fmstrat Date: Thu, 4 Feb 2021 09:23:19 -0500 Subject: [PATCH 2/3] fixed linting issues with RESTART_TIME --- src/config.ts | 2 +- src/index.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index be08e20c90..cdda6d62e6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -450,7 +450,7 @@ export const config = { page, proxy, store, - restartTime + restartTime, }; export function setConfig(newConfig: any) { diff --git a/src/index.ts b/src/index.ts index fa41c6f516..7a5b9eff47 100644 --- a/src/index.ts +++ b/src/index.ts @@ -102,7 +102,6 @@ async function stopAndExit() { Process.exit(0); } - /** * Will continually run until user interferes. */ From a7a4774b4e08c9558706ef8017353258bdb4654d Mon Sep 17 00:00:00 2001 From: Fmstrat Date: Thu, 4 Feb 2021 09:27:40 -0500 Subject: [PATCH 3/3] added documentation for RESTART_TIME --- docs/reference/application.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/application.md b/docs/reference/application.md index fe323071e9..99b2f31559 100644 --- a/docs/reference/application.md +++ b/docs/reference/application.md @@ -18,6 +18,7 @@ | `PROXY_PROTOCOL` | Protocol of proxy server, such as `socks5`. Default: `http` | | `PROXY_ADDRESS` | IP Address or fqdn of proxy server | | `PROXY_PORT` | TCP Port number on which the proxy is listening for connections. Default: `80` | +| `RESTART_TIME` | Restarts chrome after defined milliseconds. `0` for never, default: `0` | | `SCREENSHOT` | Capture screenshot of page if a card is found. Default: `true` | | `WEB_PORT` | Starts a webserver to be able to control the bot while it is running. Setting this value starts this service. |