Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Cancel enqueued task #1753

Closed
gustavopch opened this issue Jun 8, 2022 · 9 comments
Closed

[FR] Cancel enqueued task #1753

gustavopch opened this issue Jun 8, 2022 · 9 comments

Comments

@gustavopch
Copy link

gustavopch commented Jun 8, 2022

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

@google-oss-bot
Copy link

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.

@inlined
Copy link
Member

inlined commented Jun 14, 2022

Internal feature request number 235998431

@gustavopch
Copy link
Author

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.

@inlined
Copy link
Member

inlined commented Aug 9, 2022

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

@gustavopch
Copy link
Author

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

@inlined
Copy link
Member

inlined commented Aug 9, 2022

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.

@naranjamecanica
Copy link

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

@AnthonyNahas
Copy link

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

@gustavopch
Copy link
Author

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 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants