Google App Engine deferred.defer 任务未执行
Google App Engine deferred.defer task not getting executed
我有一个 Google App Engine Standard Environment 应用程序,它已经运行了一年或更长时间,但突然拒绝使用 deferred.defer.[=15 排队新的延迟任务=]
这是进行延迟调用的 Python 2.7 代码:
# Find any inventory items that reference the product, and change them too.
# because this could take some time, we'll do it as a deferred task, and only
# if needed.
if upd:
updater = deferredtasks.InvUpdate()
deferred.defer(updater.run, product_key)
我的 app.yaml 文件具有支持 deferred.defer 的必要位:
- url: /_ah/queue/deferred
script: google.appengine.ext.deferred.deferred.application
login: admin
builtins:
- deferred: on
我的延迟任务已登录,所以我应该在 运行ning 时看到它:
#-------------------------------------------------------------------------------
# DEFERRED routine that updates the inventory items for a particular product. Should be callecd
# when ANY changes are made to the product, because it should trigger a re-download of the
# inventory record for that product to the iPad.
#-------------------------------------------------------------------------------
class InvUpdate(object):
def __init__(self):
self.to_put = []
self.product_key = None
self.updcount = 0
def run(self, product_key, batch_size=100):
updproduct = product_key.get()
if not updproduct:
logging.error("DEFERRED ERROR: Product key passed in does not exist")
return
logging.info(u"DEFERRED BEGIN: beginning inventory update for: {}".format(updproduct.name))
self.product_key = product_key
self._continue(None, batch_size)
...
当我 运行 在我的开发箱上的开发环境中使用它时,一切正常。一旦我将它部署到 App Engine 服务器,清单更新永远不会完成(即延迟任务未执行),并且服务器上的日志文件中没有错误(实际上没有其他来自延迟任务的日志记录) .我知道,为了尽快让每个人都使用 Python 3,deferred.defer 库已被标记为不推荐,因为它只适用于 2.7 Python 环境,并且我计划为此转移到任务队列,但我没想到 deferred.defer 会突然停止在现有 python 环境中工作。
任何见解将不胜感激!
我很确定您不能将实例的方法传递给 appengine taskqueue,因为当您的任务 运行s 时该实例将不存在,因为它将 运行ning 在不同的过程。我实际上不明白当 运行 远程 运行 宁首先是如何工作的(并且 运行 本地并不是远程 运行 事情的准确表示)
尝试将您的代码更改为:
if upd:
deferred.defer(deferredtasks.InvUpdate.run_cls, product_key)
然后InvUpdate
是一样的但是有一个新的功能run_cls
:
class InvUpdate(object):
@classmethod
def run_cls(cls, product_key):
cls().run(product_key)
而且我仍在迁移到云任务的过程中,我的延迟任务仍然有效
我有一个 Google App Engine Standard Environment 应用程序,它已经运行了一年或更长时间,但突然拒绝使用 deferred.defer.[=15 排队新的延迟任务=]
这是进行延迟调用的 Python 2.7 代码:
# Find any inventory items that reference the product, and change them too.
# because this could take some time, we'll do it as a deferred task, and only
# if needed.
if upd:
updater = deferredtasks.InvUpdate()
deferred.defer(updater.run, product_key)
我的 app.yaml 文件具有支持 deferred.defer 的必要位:
- url: /_ah/queue/deferred
script: google.appengine.ext.deferred.deferred.application
login: admin
builtins:
- deferred: on
我的延迟任务已登录,所以我应该在 运行ning 时看到它:
#-------------------------------------------------------------------------------
# DEFERRED routine that updates the inventory items for a particular product. Should be callecd
# when ANY changes are made to the product, because it should trigger a re-download of the
# inventory record for that product to the iPad.
#-------------------------------------------------------------------------------
class InvUpdate(object):
def __init__(self):
self.to_put = []
self.product_key = None
self.updcount = 0
def run(self, product_key, batch_size=100):
updproduct = product_key.get()
if not updproduct:
logging.error("DEFERRED ERROR: Product key passed in does not exist")
return
logging.info(u"DEFERRED BEGIN: beginning inventory update for: {}".format(updproduct.name))
self.product_key = product_key
self._continue(None, batch_size)
...
当我 运行 在我的开发箱上的开发环境中使用它时,一切正常。一旦我将它部署到 App Engine 服务器,清单更新永远不会完成(即延迟任务未执行),并且服务器上的日志文件中没有错误(实际上没有其他来自延迟任务的日志记录) .我知道,为了尽快让每个人都使用 Python 3,deferred.defer 库已被标记为不推荐,因为它只适用于 2.7 Python 环境,并且我计划为此转移到任务队列,但我没想到 deferred.defer 会突然停止在现有 python 环境中工作。
任何见解将不胜感激!
我很确定您不能将实例的方法传递给 appengine taskqueue,因为当您的任务 运行s 时该实例将不存在,因为它将 运行ning 在不同的过程。我实际上不明白当 运行 远程 运行 宁首先是如何工作的(并且 运行 本地并不是远程 运行 事情的准确表示)
尝试将您的代码更改为:
if upd:
deferred.defer(deferredtasks.InvUpdate.run_cls, product_key)
然后InvUpdate
是一样的但是有一个新的功能run_cls
:
class InvUpdate(object):
@classmethod
def run_cls(cls, product_key):
cls().run(product_key)
而且我仍在迁移到云任务的过程中,我的延迟任务仍然有效