Skip to content

Commit

Permalink
fix(class/eventManagement/dispatcher): return a promise in interval ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
Rossb0b committed May 30, 2024
1 parent eebe283 commit 044028b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
30 changes: 13 additions & 17 deletions src/class/eventManagement/dispatcher.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,30 +263,26 @@ export class Dispatcher<T extends GenericEvent = GenericEvent> extends EventEmit
}
});

this.resolveTransactionsInterval = setInterval(async() => {
this.resolveTransactionsInterval = setInterval(() => {
if (!this.isWorking) {
return;
}

try {
await this.transactionHandler.resolveTransactions();
}
catch (error) {
this.logger.error({ error: error.stack }, "Failed at resolving transactions");
}
new Promise(() => {
this.transactionHandler.resolveTransactions()
.catch((error) => this.logger.error({ error: error.stack }, "Failed at resolving transactions"));
});
}, options.checkTransactionInterval ?? RESOLVE_TRANSACTION_INTERVAL).unref();

this.pingIntervalTimer = setInterval(async() => {
try {
if (!this.isWorking) {
return;
}

await this.ping();
}
catch (error) {
this.logger.error({ error: error.stack }, "Failed sending pings");
this.pingIntervalTimer = setInterval(() => {
if (!this.isWorking) {
return;
}

new Promise(() => {
this.ping()
.catch((error) => this.logger.error({ error: error.stack }, "Failed sending pings"));
});
}, this.pingInterval).unref();

this.checkLastActivityIntervalTimer = setInterval(async() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ export class TransactionHandler<T extends GenericEvent = GenericEvent> {
this.backupIncomerTransactionStore.getTransactions()
]);


const toResolve = [];
const incomerStateToUpdate = new Set<string>();
for (const incomer of incomers) {
Expand Down
2 changes: 1 addition & 1 deletion src/class/eventManagement/incomer.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getRedis,
Channel
} from "@myunisoft/redis";
import { Logger, pino } from "pino";
import { pino } from "pino";
import { P, match } from "ts-pattern";
import { ValidateFunction } from "ajv";

Expand Down

0 comments on commit 044028b

Please sign in to comment.