Skip to content

Commit

Permalink
fix(queue): add delay 1s to start event
Browse files Browse the repository at this point in the history
  • Loading branch information
wisley7l committed Oct 4, 2024
1 parent b0a4ccb commit 598eb0d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions functions/lib/events/handle-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const { logger } = require('../../context')
const limitTimeProcessing = (2 * 60 * 1000)
const Timestamp = admin.firestore.Timestamp

const delay = (timeoutMs = 1000) => new Promise(resolve => {
setTimeout(() => {
resolve(true)
}, timeoutMs)
})

const deleteEvent = (storeId, id) => {
return admin.firestore().doc(`running_events/${storeId}_${id}`)
.delete()
Expand All @@ -17,6 +23,7 @@ const createEvent = async (storeId, id, documentId) => {
if (docEventSnapshot.exists) {
const { createdAt } = docEventSnapshot.data()
if ((new Date().getTime() - new Date(createdAt).getTime()) > limitTimeProcessing) {
// remove event queue and send to last
await docEvent.delete()
return admin.firestore().doc(`${documentId}`)
.update({
Expand All @@ -27,6 +34,7 @@ const createEvent = async (storeId, id, documentId) => {
}
}

await delay()
return docEvent.set({
documentId,
storeId,
Expand Down

0 comments on commit 598eb0d

Please sign in to comment.