fix(core): Make senderId required for all command messages (#7252)
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>
This commit is contained in:
committed by
GitHub
parent
77d6e3fc07
commit
4b014286cf
@@ -5,9 +5,10 @@ import type { RedisServicePubSubPublisher } from '@/services/redis/RedisServiceP
|
||||
import * as os from 'os';
|
||||
import Container from 'typedi';
|
||||
import { License } from '@/License';
|
||||
import { MessageEventBus } from '../eventbus/MessageEventBus/MessageEventBus';
|
||||
|
||||
export function getWorkerCommandReceivedHandler(options: {
|
||||
uniqueInstanceId: string;
|
||||
queueModeId: string;
|
||||
instanceId: string;
|
||||
redisPublisher: RedisServicePubSubPublisher;
|
||||
getRunningJobIds: () => string[];
|
||||
@@ -25,16 +26,16 @@ export function getWorkerCommandReceivedHandler(options: {
|
||||
return;
|
||||
}
|
||||
if (message) {
|
||||
if (message.targets && !message.targets.includes(options.uniqueInstanceId)) {
|
||||
if (message.targets && !message.targets.includes(options.queueModeId)) {
|
||||
return; // early return if the message is not for this worker
|
||||
}
|
||||
switch (message.command) {
|
||||
case 'getStatus':
|
||||
await options.redisPublisher.publishToWorkerChannel({
|
||||
workerId: options.uniqueInstanceId,
|
||||
workerId: options.queueModeId,
|
||||
command: message.command,
|
||||
payload: {
|
||||
workerId: options.uniqueInstanceId,
|
||||
workerId: options.queueModeId,
|
||||
runningJobs: options.getRunningJobIds(),
|
||||
freeMem: os.freemem(),
|
||||
totalMem: os.totalmem(),
|
||||
@@ -53,13 +54,14 @@ export function getWorkerCommandReceivedHandler(options: {
|
||||
break;
|
||||
case 'getId':
|
||||
await options.redisPublisher.publishToWorkerChannel({
|
||||
workerId: options.uniqueInstanceId,
|
||||
workerId: options.queueModeId,
|
||||
command: message.command,
|
||||
});
|
||||
break;
|
||||
case 'restartEventBus':
|
||||
await Container.get(MessageEventBus).restart();
|
||||
await options.redisPublisher.publishToWorkerChannel({
|
||||
workerId: options.uniqueInstanceId,
|
||||
workerId: options.queueModeId,
|
||||
command: message.command,
|
||||
payload: {
|
||||
result: 'success',
|
||||
|
||||
Reference in New Issue
Block a user