General Actions to handlers Refacto

This commit is contained in:
STEINNI
2026-06-20 18:50:26 +00:00
parent 7435d96135
commit 44a84c64ec
56 changed files with 832 additions and 973 deletions
+33
View File
@@ -0,0 +1,33 @@
export function dispatchEvents(redisCnx, msg, chan, eventHandlers) {
const eventType = msg.eventType
if(!eventType || typeof(eventType) !== 'string') return(false)
let handled = false
for(const [channelPattern, byType] of Object.entries(eventHandlers ?? {})) {
if(!redisCnx.matchesChan(chan, channelPattern)) continue
const handlers = byType[eventType]
if(!handlers?.length) continue
for(const handle of handlers) {
try {
handle.call(redisCnx, msg, chan)
} catch(err) {
console.error(
`[${redisCnx.redisId}] Event ${eventType} on ${chan} failed:`,
err
)
}
}
handled = true
}
if(!handled && redisCnx.debug) {
console.log(`[${redisCnx.redisId}] Unhandled event ${eventType} on ${chan}`)
}
return(handled)
}