From 677af51e988ebab9f4f9a03fcced4eb3395ea194 Mon Sep 17 00:00:00 2001 From: andrewEze Date: Tue, 24 Dec 2024 13:04:12 +0200 Subject: [PATCH] Fix job methods exec. --- server/src/jobs/emails.mjs | 2 +- server/src/jobs/job.mjs | 44 ++++++--------------------------- server/src/jobs/tx-check.mjs | 2 +- server/src/jobs/wallet-data.mjs | 4 +-- 4 files changed, 12 insertions(+), 40 deletions(-) diff --git a/server/src/jobs/emails.mjs b/server/src/jobs/emails.mjs index 354a84d37..a55443c86 100644 --- a/server/src/jobs/emails.mjs +++ b/server/src/jobs/emails.mjs @@ -63,7 +63,7 @@ class EmailsJob extends CommonJob { this.postMessage(`Process notifications - ${notifications.length}`); - const handleNotifications = notifications => async () => { + const handleNotifications = async notifications => { if (this.isCancelled) return false; this.postMessage(`Processing notifications id - ${notifications.map(n => n.id)}`); diff --git a/server/src/jobs/job.mjs b/server/src/jobs/job.mjs index b84c0a02d..514e13b44 100644 --- a/server/src/jobs/job.mjs +++ b/server/src/jobs/job.mjs @@ -34,49 +34,21 @@ class CommonJob { async execute() {} async executeActions(methods) { - const amount = methods.length; + await Promise.allSettled(methods); + } - await new Promise(resolve => { - let intervalId = null; - let itemsResolved = 0; - methods.forEach(async method => { + async executeMethodsArray(methods) { + const execMethods = async methodsArray => { + for (const method of methodsArray) { try { await method(); } catch (e) { // } - ++itemsResolved; - }); - intervalId = setInterval(() => { - if (itemsResolved === amount) { - clearInterval(intervalId); - resolve(); - } - }, 500); - }); - } + } + }; - async executeMethodsArray(methods, amount) { - await new Promise(resolve => { - let intervalId = null; - let itemsResolved = 0; - methods.forEach(async methods => { - for (const method of methods) { - try { - await method(); - } catch (e) { - // - } - ++itemsResolved; - } - }); - intervalId = setInterval(() => { - if (itemsResolved === amount) { - clearInterval(intervalId); - resolve(); - } - }, 500); - }); + await Promise.allSettled(methods.map(methodsArray => execMethods(methodsArray))); } } diff --git a/server/src/jobs/tx-check.mjs b/server/src/jobs/tx-check.mjs index e9c6cc17b..d754fcfed 100644 --- a/server/src/jobs/tx-check.mjs +++ b/server/src/jobs/tx-check.mjs @@ -45,7 +45,7 @@ class TxCheckJob extends CommonJob { const maxRetries = Number(await Var.getValByKey(VARS_KEYS.DEFAULT_MAX_RETRIES)); - const processTxItems = items => async () => { + const processTxItems = async items => { if (this.isCancelled) return false; const { orderId } = items[0]; diff --git a/server/src/jobs/wallet-data.mjs b/server/src/jobs/wallet-data.mjs index 9aba77bb0..ae18c79d3 100644 --- a/server/src/jobs/wallet-data.mjs +++ b/server/src/jobs/wallet-data.mjs @@ -680,7 +680,7 @@ class WalletDataJob extends CommonJob { let offset = 0; let domainsWatchlistOffset = 0; - const processWallet = wallet => async () => { + const processWallet = async wallet => { if (this.isCancelled || !wallet.User.email) return false; if (DEBUG_INFO) this.postMessage(`Process wallet - ${wallet.id}`); @@ -720,7 +720,7 @@ class WalletDataJob extends CommonJob { return true; }; - const processDomainWatchlist = domainsWatchlistItem => async () => { + const processDomainWatchlist = async domainsWatchlistItem => { if (this.isCancelled) return false; if (DEBUG_INFO)