Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cancel a task enqueued on Firebase Functions?

I'm talking about this: https://firebase.google.com/docs/functions/task-functions

I want to enqueue tasks with the scheduleTime parameter to run in the future, but I must be able to cancel those tasks.

I expected it would be possible to do something like this pseudo code:

const task = await queue.enqueue({ foo: true })

// Then...
await queue.cancel(task.id)

I'm using Node.js. In case it's not possible to cancel a scheduled task with firebase-admin, can I somehow work around it by using @google-cloud/tasks directly?

PS: I've also created a feature request: https://github.com/firebase/firebase-admin-node/issues/1753

like image 472
gustavopch Avatar asked Oct 18 '25 02:10

gustavopch


1 Answers

In latest releases a feature was added to delete the tasks. You can pass an id to the TaksOptions

const queue = getFunctions().taskQueue("yourQueue");
// Enqueue and pass id to TaksOptions
await queue.enqueue({ 
...data
}, 
{
  id: idYouWillBeUsingToDelete,
  ...taskOptions
});

Delete the task

const queue = getFunctions().taskQueue("yourQueue");
// Use de delete method
await queue.delete(idYouWillBeUsingToDelete)
like image 51
Carlos Avatar answered Oct 20 '25 14:10

Carlos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!