I recently came across an article on Firebase task functions published by Google, where it was mentioned that tasks should be dispatched in a first-in-first-out (FIFO) order. Despite trying different settings, the tasks are not being processed in the correct order. Is it even possible to ensure FIFO processing of Firebase tasks? Please refer to the code snippet and result image attached.
export const backupApod = functions.tasks
.taskQueue({
retryConfig: {
maxAttempts: 5,
minBackoffSeconds: 60,
},
rateLimits: {
maxConcurrentDispatches: 1,
},
})
.onDispatch(async (data) => {
try {
await FireStore.getDatabase()
.collection("queueTest")
.doc("test")
.set(
{
test: firestore.FieldValue.arrayUnion(data.id),
},
{ merge: true }
);
await LoggerService.info(JSON.stringify(data));
} catch (error) {
await LoggerService.error(JSON.stringify(error) as any);
}
});
export const enqueueBackupTasks = functions.https.onRequest(async (_request, response) => {
const queue = getFunctions(app).taskQueue("backupApod");
const enqueues = [];
for (let i = 0; i <= 100; i += 1) {
enqueues.push(
queue.enqueue(
{ id: `task-${i}` },
{
dispatchDeadlineSeconds: 60 * 5, // 5 minutes
}
)
);
}
await Promise.all(enqueues);
response.sendStatus(200);
});
// Attempted adding tasks synchronously and pausing the queue. Upon resuming the queue, the order is still incorrect.
export const enqueueBackupTasks = functions.https.onRequest(async (_request, response) => {
const queue = getFunctions(app).taskQueue("backupApod");
for (let i = 0; i <= 100; i += 1) {
await queue.enqueue(
{ id: `task-${i}` },
{
dispatchDeadlineSeconds: 60 * 5, // 5 minutes
}
);
}
response.sendStatus(200);
});