I want to load up several tasks in the Task Queue (push) and then determine when the group of tasks I've added to the queue have been completed. I have the following code:
task = taskqueue.add(url='/task')
import time
while not task.was_deleted:
logging.info('not deleted yet')
time.sleep(1)
This loops indefinitely. I expected that once the task was processed and deleted the 'was_deleted' parameter would return True. But even when the task is deleted, 'was_deleted' continues to return false. Here is what the docs say:
task.was_deleted: "True if this task has been successfully deleted." https://developers.google.com/appengine/docs/python/taskqueue/tasks#Task_was_deleted
If a pull task is created successfully, your application needs to delete the task after processing. The system may take up to seven days to recognize that a task has been deleted; during this time, the task name remains unavailable. Attempting to create another task during this time with the same name will result in an "item exists" error. The system offers no method to determine if deleted task names are still in the system. To avoid these issues, we recommend that you let App Engine generate the task name automatically. https://developers.google.com/appengine/docs/python/taskqueue/overview#Task_Concepts
This paragraph seems to suggest that you cannot immediately determine when a given task has been deleted. Is this correct?
My questions:
- What is the intended use for was_deleted
- How do you determine when a specific task (or group of tasks) added to the push queue has been completed
I can't answer your first question, but for the second question, I have a similar need as yours.
What I have done is to group the tasks that I want to check for completion in a queue for them, and using the QueueStatistics class you can see the number of remaining tasks for that queue.
The following code illustrates how to get that data. You can try it in the interactive console.