Determine if a task has been deleted GAE Python

▼魔方 西西 提交于 2019-12-11 08:18:01

问题


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:

  1. What is the intended use for was_deleted
  2. How do you determine when a specific task (or group of tasks) added to the push queue has been completed

回答1:


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.

from google.appengine.api import taskqueue

statsList = taskqueue.QueueStatistics.fetch(taskqueue.Queue("default"))

print(statsList.tasks)


来源:https://stackoverflow.com/questions/13504389/determine-if-a-task-has-been-deleted-gae-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!