-
-
Notifications
You must be signed in to change notification settings - Fork 2
Initial version #1
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
base: master
Are you sure you want to change the base?
Conversation
|
Config file:
@MerdyNumber1 |
|
Regarding prisma:
|
|
|
Dependency injection make sense when you want to ensure that same instance is shared across modules. There is only one instance of Prisma. The DI is not needed here. Anyway, I advice you to not use this pattern. It make sense if you have right tools, where the DI is handled by a special lib (an example are decorators in Nest.js). But passing the instance manually to every function just increases the code complexity. @MerdyNumber1 |
|
I suggest reviewing the architecture of I recommend moving a significant part of the logic into designated channels:
Both classes should extend from Usage: const transactionsChannel = new TransactionsChannel();
transactionsChannel.on("newTransaction", (transaction) => {
// perform a push notification action if needed
});
const messagesChannel = new MessagesChannel();
messagesChannel.on("newTransaction", (transaction) => {
// save/remove Device token from DB
});Since the architecture is event-based, you probably don't need a cron job. You may need a queue to batch notifications if FCM allow this. |
| logger.info( | ||
| `Spawned transaction parser job with ${config.app.txCheckInterval} interval` | ||
| ) | ||
| return schedule(config.app.txCheckInterval, async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using schedule, you can use a regular setTimeout that invokes itself after each iteration. In this case, you can remove the this.isLocked check, as invoking the callback multiple times won't be possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally add destroy method to this class that will:
- Stop the timer
- Stop listening for adamantClient events (
adamantClient.socket.off(callback))
Invoke transactionsChannel.destroy() from main.ts on SIGINT/SIGTERM
src/events/handlers.ts
Outdated
| where: { admAddress: tx.recipientId } | ||
| }) | ||
|
|
||
| devices = devices.filter((device) => device.admAddress === tx.recipientId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need to filter devices here if you already used where: { admAddress: tx.recipientId } on line 16.
src/events/handlers.ts
Outdated
| await Promise.all( | ||
| devices.map((device) => { | ||
| processTransactionToNotify(tx, device) | ||
| }) | ||
| ) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to use cargoQueue from async lib. I see that FCM supports notification batching. This should improve performance when sending a large number of notifications.
Logs: src/modules/logger.ts error TS2742: The inferred type cannot be named without a reference to 'pino'

No description provided.