use simple pup/sub chanel

This commit is contained in:
smart_ex 2022-06-22 14:34:27 +10:00
parent 2c20febcab
commit 66dc7efa60
4 changed files with 9 additions and 15 deletions

View File

@ -2,4 +2,3 @@ timeout 0
tcp-keepalive 0
databases 1
save 60 100000
notify-keyspace-events KAE

View File

@ -59,7 +59,7 @@ export class HealthService {
async getStatus() {
const { errorsLog, errorsCode } = await this._getErrors();
if (errorsCode['NETWORK_ERROR'] > 5) {
if (errorsCode['NETWORK_ERROR'] > 6) {
await this.setStatus({ status: false, error: 'Network error' });
}
const heathStatus = await this._getStatus();
@ -87,7 +87,7 @@ export class HealthService {
}
async pushAlert(alert: Alert) {
await this.store.client.rpush('alerts:list', JSON.stringify(alert));
await this.store.publisher.publish('user-notify', JSON.stringify(alert));
}
private async _checkBalance(value, currency: 'MAIN' | 'TORN') {
@ -126,7 +126,6 @@ export class HealthService {
throw new RelayerError(tornStatus.message, 'INSUFFICIENT_TORN_BALANCE');
}
}
}
type HealthData = {

View File

@ -47,16 +47,13 @@ export class NotifierService {
}
async subscribe() {
const sub = await this.store.subscriber;
sub.subscribe('__keyspace@0__:alerts:list', 'rpush');
sub.on('message', async (channel, event) => {
if (event === 'rpush') {
const messages = await this.store.client.rpop('alerts:list', 10);
messages?.forEach(message => {
this.processAlert(message);
});
}
});
this.store.subscriber.subscribe('user-notify');
this.store.subscriber.on('message', async (channel, message) => {
await this.processAlert(<string>message);
},
);
}
send(message: string, level: Levels) {

View File

@ -10,7 +10,6 @@
"outDir": "./build",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"resolveJsonModule": true