firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

[FR] Cancel enqueued task

Open gustavopch opened this issue 2 years ago • 7 comments

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

gustavopch avatar Jun 08 '22 16:06 gustavopch

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.

google-oss-bot avatar Jun 08 '22 16:06 google-oss-bot

Internal feature request number 235998431

inlined avatar Jun 14 '22 17:06 inlined

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.

gustavopch avatar Jul 25 '22 17:07 gustavopch

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("")

inlined avatar Aug 09 '22 04:08 inlined

Thanks for the update, @inlined. The IDs generated by Firestore are good for sharding, right?

gustavopch avatar Aug 09 '22 12:08 gustavopch

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.

inlined avatar Aug 09 '22 23:08 inlined

Somewhat related: I wanted to set task name myself, so I can use the Cloud Tasks automatic deduplication.

naranjamecanica avatar Sep 05 '22 12:09 naranjamecanica

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

AnthonyNahas avatar Jan 15 '23 11:01 AnthonyNahas

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 🥳

gustavopch avatar Jul 12 '23 20:07 gustavopch