refactor(core): Include self-sending and debouncing in pubsub commands (#11149)

This commit is contained in:
Iván Ovejero
2024-10-08 11:18:12 +02:00
committed by GitHub
parent 1ca14946d9
commit 1ded08bf7e
6 changed files with 41 additions and 15 deletions

View File

@@ -70,12 +70,15 @@ export class Subscriber {
// #region Commands
setCommandMessageHandler() {
const handlerFn = debounce((str: string) => {
const msg = this.parseCommandMessage(str);
if (msg) this.eventService.emit(msg.command, msg.payload);
}, 300);
const handlerFn = (msg: PubSub.Command) => this.eventService.emit(msg.command, msg.payload);
const debouncedHandlerFn = debounce(handlerFn, 300);
this.setMessageHandler('n8n.commands', handlerFn);
this.setMessageHandler('n8n.commands', (str: string) => {
const msg = this.parseCommandMessage(str);
if (!msg) return;
if (msg.debounce) debouncedHandlerFn(msg);
else handlerFn(msg);
});
}
private parseCommandMessage(str: string) {
@@ -91,7 +94,10 @@ export class Subscriber {
const queueModeId = config.getEnv('redis.queueModeId');
if (msg.senderId === queueModeId || (msg.targets && !msg.targets.includes(queueModeId))) {
if (
!msg.selfSend &&
(msg.senderId === queueModeId || (msg.targets && !msg.targets.includes(queueModeId)))
) {
this.logger.debug('Disregarding message - not for this instance', msg);
return null;