Skip to content

Commit

Permalink
fix(handle-events): check document exists
Browse files Browse the repository at this point in the history
  • Loading branch information
wisley7l committed Sep 17, 2024
1 parent 9413d36 commit 155dcc6
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions functions/lib/events/handle-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,28 +168,28 @@ const eventQueueController = async (change, context) => {
const isProcessing = processingTime && processingTime < limiteTime
logger.info(`${runDocId} => ${documentId} ${isProcessing}`)
if (documentId && (!runDocId || !isProcessing)) {
// ler o documento
// adiciona no docRun e
// processing
// e executo
// quando finalizar remove o docRun
const docQueue = await firestore().doc(documentId).get()
if (docQueue.exists) {
console.log(docQueue.data())
}

await docController.ref.update({
runDocId: documentId,
processingAt: now
})
await docController.ref.update({
runDocId: documentId,
processingAt: now
})

await runDoc(documentId, docQueue)
.then(async () => {
await docController.ref.update({
runDocId: firestore.FieldValue.delete()
await runDoc(documentId, docQueue)
.then(async () => {
await docController.ref.update({
runDocId: firestore.FieldValue.delete()
})
logger.info(`> finish ${documentId}`)
})
logger.info(`> finish ${documentId}`)
} else {
logger.info(`> arrayRemove ${documentId}`)
await docController.ref.update({
queue: firestore.FieldValue.arrayRemove(documentId),
updatedAt: new Date().toISOString()
})
}
}
}

Expand Down

0 comments on commit 155dcc6

Please sign in to comment.