Based of this article recently published by Google I am trying to dispatch firebase tasks in the order(first in first out) of the queue. But no matter what setting I try it does not process tasks in order of the queue. Please see code attached and the result image. Is it even possible to process firebase task in an order(fifo)?
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);
});
// Event tried adding tasks synchronously, then pausing queue. When resume the queue the order is also not correct
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);
});
