user2686101
user2686101

Reputation: 352

How to retrieve a queued task with task_name

I am building a Python application that works with taskqueue in the following flow

  1. Add a pull task to taskqueue by calling taskqueue.add()
  2. Lease the same task by calling taskqueue.lease_tasks()
  3. After some time, we may want to shorten the lease time by calling taskqueue.modify_task_lease()

The problem is, those 3 steps happen in different web sessions. At step 3, the modify_task_lease() function need a task instance as argument, while I only have task_name in hand, which is passed from step 2 with web hooks.

So is there any way to retrieve a task with its name?

In the document, I found delete_tasks_by_name(), but there is no modify_task_lease_by_name(), which is exactly what I wanted to do.

Upvotes: 1

Views: 120

Answers (1)

Dan Cornilescu
Dan Cornilescu

Reputation: 39824

The delete_tasks_by_name() is just a wrapper around delete_tasks_by_name_async(), which is implemented as

if isinstance(task_name, str):
  return self.delete_tasks_async(Task(name=task_name), rpc)
else:
  tasks = [Task(name=name) for name in task_name]
  return self.delete_tasks_async(tasks, rpc)

So I guess you could similarly use the Task() constructor to obtain the task instance needed by modify_task_lease():

modify_task_lease(Task(name=your_task_name), lease_seconds)

Upvotes: 2

Related Questions