Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix job methods exec. #1960

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/src/jobs/emails.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
Expand Down
44 changes: 8 additions & 36 deletions server/src/jobs/job.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/jobs/tx-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions server/src/jobs/wallet-data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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)
Expand Down