chore: Add error handling and processing status flag to knowledge queue subscription

This commit is contained in:
n4ze3m 2024-07-16 10:09:31 +05:30
parent 9c8584f1c4
commit cecb447b46

View File

@ -3,4 +3,22 @@ import PubSub from "pubsub-js"
export const KNOWLEDGE_QUEUE = Symbol("queue")
PubSub.subscribe(KNOWLEDGE_QUEUE, processKnowledge)
let isProcessing = false
PubSub.subscribe(KNOWLEDGE_QUEUE, async (msg, id) => {
try {
isProcessing = true
await processKnowledge(msg, id)
isProcessing = false
} catch (error) {
console.error(error)
isProcessing = false
}
})
window.addEventListener("beforeunload", (event) => {
if (isProcessing) {
event.preventDefault()
event.returnValue = ""
}
})