我有一个由后端提供服务的请求队列,当队列为空时,我需要触发另一个脚本。在
目前,我在从队列中租赁任务的方法中使用了一个非常粗糙的检测,因此如果返回的任务列表为空,我们就假定没有更多的任务可以租赁并触发下一步。然而,虽然这在大多数情况下都是有效的,但是偶尔租约请求似乎返回一个空列表,即使有任务可用。在
总之,我认为更好的方法是使用队列的fetch_statistics方法。这样,脚本就可以监视请求队列中发生的事情,并知道队列中不再有项目了。现在,这显然可以通过restapi用于队列,但是在内部使用时,使用它似乎有些落后。在
所以我在做Queue.fetch_统计信息()调用,但它抛出错误。我试着把这个错误输入到Google中,但是没有返回任何结果。stackoverflow也是。在
它总是抛出:
AttributeError: type object 'QueueStatistics' has no attribute '_QueueStatistics__TranslateError'
我的代码是:
^{pr2}$有人能解释一下吗?我是不是在做一些很蠢的事?在
任务队列统计API现在已经有文档记录并可公开使用。错误不再发生。在
为了避免对其他人有用,这里有一个示例函数,可以让您开始从应用程序获取队列信息。这只是一个例子,可以更好地处理错误,但它应该能让您启动并运行。以前我们使用过Taskqueue客户机,但我认为这有点过头了,因为我们可以在代码中租赁和删除,所以我使用了app identity,而且效果很好。在
别忘了更新你的队列.yaml应用程序标识的acl
^{pr2}$我希望有人发现这个有用。在
同时,我已经发布了一个特性请求,这样我们就可以用Queue对象来完成这个任务,如果你也想要的话,请去给它加上星号。http://goo.gl/W8Pk1
你得到的具体错误的直接原因似乎是代码中的一个错误;Queue.fetch_统计信息电话()QueueStatistics.fetch()调用QueueStatistics.\u FetchMultipleQueues(),它显然遇到了apiproxy_错误.ApplicationError然后尝试调用cls.\uu TranslateError(),但QueueStatistics类上没有此类方法。在
我不知道ApplicationError的深层原因,但这可能意味着生产运行时还不支持该功能。在
相关问题 更多 >
编程相关推荐