all commands sent between main instance and workers need to contain a server id to prevent senders from reacting to their own messages, causing loops this PR makes sure all sent messages contain a sender id by default as part of constructing a sending redis client. --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
30 lines
903 B
TypeScript
30 lines
903 B
TypeScript
import { Service } from 'typedi';
|
|
import { WORKER_RESPONSE_REDIS_LIST } from './RedisServiceHelper';
|
|
import type { RedisServiceWorkerResponseObject } from './RedisServiceCommands';
|
|
import { RedisServiceBaseSender } from './RedisServiceBaseClasses';
|
|
|
|
@Service()
|
|
export class RedisServiceListSender extends RedisServiceBaseSender {
|
|
async init(): Promise<void> {
|
|
await super.init('list-sender');
|
|
}
|
|
|
|
async prepend(list: string, message: string): Promise<void> {
|
|
if (!this.redisClient) {
|
|
await this.init();
|
|
}
|
|
await this.redisClient?.lpush(list, message);
|
|
}
|
|
|
|
async append(list: string, message: string): Promise<void> {
|
|
if (!this.redisClient) {
|
|
await this.init();
|
|
}
|
|
await this.redisClient?.rpush(list, message);
|
|
}
|
|
|
|
async appendWorkerResponse(message: RedisServiceWorkerResponseObject): Promise<void> {
|
|
await this.prepend(WORKER_RESPONSE_REDIS_LIST, JSON.stringify(message));
|
|
}
|
|
}
|