How can I check whether I have already enqueued a task before?

104 Views Asked by At

I'd like to add a task on the App Engine Task Queue, but only if it hasn't been enqueued before. How can I check whether its already in queue or not? Wasn't obvious from the task queue API, but maybe I missed it. They key to the task (param?) would be user_id. Use case: I keep checking for new messages every minute. This needs to happen very frequently. However, sometimes there are other jobs in this queue (they all need to be part of the same queue because they are using an external service, Gmail API, which has a rate limit of 10 qps, which I can only guarantee by rate limiting the queue). When these heavy processes run, they backlog the queue. To avoid this, I'd like to check whether a incremental-fetch task has previously been enqueued, and only enqueue if it hasn't. What is the best practice to achieve something like this?

2

There are 2 best solutions below

0
On

You can use task names for this purpose.

0
On

I would add a tag to the task then do a lease_task_by_tag with a lease_seconds set to 0. If its empty then I can safely create a new one.