firebase-admin-node
firebase-admin-node copied to clipboard
[FR] Cancel enqueued task
Is your feature request related to a problem? Please describe. Not applicable.
Describe the solution you'd like I need to be able to cancel a task that was enqueued, like this pseudo-code:
const task = await queue.enqueue({ foo: true })
// Then...
await queue.cancel(task.id)
Describe alternatives you've considered
Maybe there's some way to cancel the task using @google-cloud/tasks
directly, but I didn't try yet.
EDIT: Apparently, it's not possible because the task ID is not returned by firebase-admin
.
Additional context I've also asked on StackOverflow, but I think it's really a missing feature: https://stackoverflow.com/questions/72549309/how-to-cancel-a-task-enqueued-on-firebase-functions
I found a few problems with this issue:
- I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
- This issue does not seem to follow the issue template. Make sure you provide all the required information.
Internal feature request number 235998431
Hey, I'd like to add here that being able to specify the name of the task would be better for me than getting an auto-generated name.
Use-case: I want to have a Firestore-triggered Cloud Function that will enqueue the task when a document is created. If I can specify the task name, I just create the document with a taskName
field and pass it to queue.enqueue()
. Otherwise, if the task name is always automatically generated, I'll need to update the document to store it and then protect against infinite recursion because changing the document will retrigger the function. I'd rather not have to deal with a possible infinite recursion.
Both features have been submitted for API review, which is a formal step before any implementation can begin. One thing I realized during my research though is that autogenerated document IDs make horrible task IDs. Task queue IDs are used for sharding, so sequences of increasing numbers (like timestamps) cause scaling problems. Automatic document IDs are based on timestmaps and will cause problems. A solution is to reverse the string with mystring.split("").reverse().join("")
Thanks for the update, @inlined. The IDs generated by Firestore are good for sharding, right?
Indeed. That code is for truly unique IDs. I thought Firestore was like the Realtime Database, which uses base64 encoded timestamps along with an anti-collision nonce.
Somewhat related: I wanted to set task name myself, so I can use the Cloud Tasks automatic deduplication.
I am running into the same issue.
I want to prevent the tasks in the queue from being duplicated. It seems the only solution is to manually set a task name in the code. When this is supported than I wont need to clear or cancels tasks by myself
They just released v11.10.0 which provides a way to cancel enqueued tasks: https://github.com/firebase/firebase-admin-node/releases/tag/v11.10.0 🥳