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 tcp-keepalive 0
databases 1 databases 1
save 60 100000 save 60 100000
notify-keyspace-events KAE

View File

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

View File

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

View File

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