AppEngine 任务队列 API 调用因 TaskAlreadyExistsError 而增加
我使用 deferred
将任务放入 AppEngine 应用程序的默认队列中,类似于 这种方法。
我使用每 5 秒更改一次的时间戳来命名该任务。在此期间,对具有相同名称的队列进行了大量调用,导致出现 TaskAlreadyExistsError
这很好。问题是,当我检查配额时,每次调用的“任务队列 API 调用”都会增加,而不仅仅是那些实际放入队列的调用。
我的意思是,如果您查看配额:Task Queue API Calls: 34,017 of 100,000
并与实际队列调用进行比较:/_ah/queue/deferred - 2.49K
这里是处理队列的代码:
try:
deferred.defer(function_call, params, _name=task_name, _countdown=int(interval/2))
except (taskqueue.TaskAlreadyExistsError, taskqueue.TombstonedTaskError):
pass
我想这就是它的工作方式。有没有好的办法解决配额问题呢?除了上面的 try/catch 之外,我可以使用 memcache 存储 task_name
并检查任务是否已添加吗?或者有没有办法在不使用任务队列 Api 调用的情况下检查任务是否已存在?
I'm using deferred
to put tasks in the default queue in a AppEngine app similar to this approach.
Im naming the task with a timestamp that changes every 5 second. During that time a lot of calls are made to the queue with the same name resulting in a TaskAlreadyExistsError
which is fine. The problem is when I check the quotas the "Task Queue API Calls" are increasing for every call made, not only those who actually are put in the queue.
I mean if you look at the quota: Task Queue API Calls: 34,017 of 100,000
and compare to the actual queue calls: /_ah/queue/deferred - 2.49K
Here is the code that handles the queue:
try:
deferred.defer(function_call, params, _name=task_name, _countdown=int(interval/2))
except (taskqueue.TaskAlreadyExistsError, taskqueue.TombstonedTaskError):
pass
I suppose that is the way it works. Is there a good way to solve the problem with the quota? Can I use memcache to store the task_name
and check if the task has been added besides the above try/catch? Or is there a way to check if the task already exists without using Task Queue Api Calls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢您指出情况是这样,因为我没有意识到,但同样的问题一定正在影响我。
据我所知,是的,将由任务名称组成的内容放入内存缓存中应该可以正常工作,然后如果您想减少对内存缓存的命中,您也可以在实例中本地存储该标志。
Thanks for pointing out that this is the case, because I didn't realise, but the same problem must be affecting me.
As far as I can see yeah, throwing something into memcache comprised of the taskname should work fine, and then if you want to reduce those hits on memcache you can store the flag locally also within the instance.
解决配额问题的“好方法”是消除对任务队列 API 注定失败的调用。
_name
您每 5 秒使用一次更改,如果您提高任务队列的执行率,这可能不会成为瓶颈。但您也可以使用_countdown
添加任务。The "good way" to solve the quota problem is eliminating destined-to-fail calls to Task Queue API.
_name
you are using changes every 5 seconds which might not be a bottleneck if you increase the execution rate of your Task Queue. But you also add Tasks using_countdown
.