确定任务是否已被删除GAE Python [英] Determine if a task has been deleted GAE Python

查看:178
本文介绍了确定任务是否已被删除GAE Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Task Queue中加载多个任务(push),然后确定我已经添加到队列中的任务组何时完成。我有以下代码:

$ p $ task = taskqueue.add(url ='/ task')

导入时间
,而不是task.was_deleted:
logging.info('尚未删除')
time.sleep(1)

无限循环。我预计,一旦任务被处理并删除,'was_deleted'参数将返回True。但即使任务被删除,'was_deleted'仍然返回false。以下是文档的说明:

task.was_deleted:如果此任务已成功删除,则为true。
https://developers.google.com/appengine/docs / python / taskqueue / tasks#Task_was_deleted



如果拉任务成功创建,应用程序需要在处理后删除任务。系统可能需要七天时间才能确认任务已被删除;在此期间,任务名称仍然不可用。尝试在此期间创建具有相同名称的另一个任务将导致存在项目错误。系统不提供确定删除的任务名称是否仍在系统中的方法。为避免这些问题,我们建议您让App Engine自动生成任务名称。
https://developers.google.com/appengine/docs / python / taskqueue / overview#Task_Concepts



这一段似乎暗示您无法立即确定给定任务何时被删除。这是正确的吗?



我的问题:


  1. was_deleted

  2. 您如何确定添加到推送队列的特定任务(或任务组)已完成


解决方案

我无法回答你的第一个问题,但对于第二个问题,我有和你一样的需求。

我所做的是将我想要检查完成的任务分组在队列中,并使用QueueStatistics类可以看到剩余任务的数量对于该队列。



以下代码说明如何获取该数据。您可以在交互式控制台中试用它。

  from google.appengine.api import taskqueue 

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

print(statsList.tasks)


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

解决方案

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)

这篇关于确定任务是否已被删除GAE Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆