简体   繁体   English

如何识别GAE提取队列中是否已经存在任务?

[英]How to identify whether task exists already within GAE pull queue?

Before adding a task to the pull queue, I have to confirm whether same task exists already within queue, if exists should skip task adding to queue. 在将任务添加到提取队列之前,我必须确认队列中是否已经存在相同的任务,如果存在,则应跳过将任务添加到队列中。 Adding task with name doesn't work for me as it doesn't expire until seven days from the queue even deleted. 添加具有名称的任务对我不起作用,因为直到从队列中删除7天后它才到期。

We can list tasks using REST API . 我们可以使用REST API列出任务。 In the same way, can we get the list of tasks within GAE module or is there any other way to find whether task exists in the queue within Google App Engine module? 同样,我们可以获取GAE模块中的任务列表,还是可以通过其他方法来查找Google App Engine模块中的队列中是否存在任务?

Thanks 谢谢

If task names does not work with logic of your app you can create a corresponding db entity (empty, just a key) that would serve as a flag that the tasks is in the queue. 如果任务名称与应用程序的逻辑不兼容,则可以创建一个相应的数据库实体(空,只是一个键),该实体将用作任务在队列中的标志。 You should put it to db in transaction with a task and delete when task completed. 您应该将其放入与任务一起进行事务处理的数据库中,并在任务完成时删除。

It would cost you 1 read & 4 write (2 for insert & 2 for delete) operations per each task - nothing comes free. 每个任务将花费您1个读取和4个写入(2个用于插入&2​​个用于删除)操作-没有免费的东西。

As alternative you can consider to have some counter in your business entity that would be a part of task name. 或者,您可以考虑在业务实体中有一些计数器,该计数器将成为任务名称的一部分。

Let's say you have entity User and a property TaskCounter. 假设您有实体用户和属性TaskCounter。

Then you would add task as: 然后,您将任务添加为:

tasks.add(taskName="TASKNAME" + str(user.id) + str(user.TaskCounter)) - that would insure you can have just 1 active task per entity. task.add(taskName =“ TASKNAME” + str(user.id)+ str(user.TaskCounter))-这样可以确保每个实体只能有1个活动任务。 Of course you would need to update the property when the task finishes. 当然,任务完成后,您将需要更新属性。 If you update the entity in the task anyway it costs you almost nothing. 无论如何,如果您在任务中更新实体,则几乎不会花费任何费用。

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

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