简体   繁体   English

确定是否已删除任务GAE Python

[英]Determine if a task has been deleted GAE Python

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. 我希望一旦任务被处理并删除,“ was_deleted”参数将返回True。 But even when the task is deleted, 'was_deleted' continues to return false. 但是,即使删除任务,“ was_deleted”仍将返回false。 Here is what the docs say: 这是文档所说的:

task.was_deleted: "True if this task has been successfully deleted." task.was_deleted:“如果已成功删除此任务,则为真。” https://developers.google.com/appengine/docs/python/taskqueue/tasks#Task_was_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; 系统最多可能需要7天才能识别出任务已被删除; 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. 为避免这些问题,我们建议您让App Engine自动生成任务名称。 https://developers.google.com/appengine/docs/python/taskqueue/overview#Task_Concepts 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 was_deleted的预期用途是什么
  2. 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. 我要做的是将要检查其完成情况的任务分组在队列中,使用QueueStatistics类,您可以看到该队列剩余的任务数。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM