Python Appengine管道,如何让函数在管道工作完成后立即执行
我尝试添加一个回调函数,该函数在Log2Bq完成后执行。 但我使用Python Appengine管道,如何让函数在管道工作完成后立即执行,python,google-app-engine,pipeline,Python,Google App Engine,Pipeline,我尝试添加一个回调函数,该函数在Log2Bq完成后执行。 但我使用pipeline.After或pipeline.inoder都不起作用。在下面的代码示例中,taskqueue将立即执行,而不等待Log2Bq。为了解决这个问题, 我是否需要创建另一个管道来保存taskqueue,以使执行顺序正常工作 class Log2Stat(base_handler.PipelineBase): def run(self, _date): print "start track"
pipeline.After
或pipeline.inoder
都不起作用。在下面的代码示例中,taskqueue将立即执行,而不等待Log2Bq。为了解决这个问题,
我是否需要创建另一个管道来保存taskqueue,以使执行顺序正常工作
class Log2Stat(base_handler.PipelineBase):
def run(self, _date):
print "start track"
with pipeline.InOrder():
yield pipelines.Log2Bq()
print "finish track"
taskqueue.add(
url='/worker/update_daily_stat',
params={
"date": str(_date.date())
}
)
pipeline.inoorder()
和pipeline.After()
仅用于排序管道执行,而不是代码执行
有一个名为finalized的方法,它在写入最后一个输出后立即执行,也就是说,当您的Log2Bq()
管道完成它的执行时,因此:
class Log2Stat(base_handler.PipelineBase):
def run(self, _date):
print "start track"
yield pipelines.Log2Bq()
def finalized(self):
print "finish track"
taskqueue.add(
url='/worker/update_daily_stat',
params={
"date": str(_date.date())
}
)
如果要使用pipeline.inoorder()或pipeline.After(),则应将taskqueue代码包装在其他管道中,并在pipelines.Log2Bq()之后生成它。
谢谢。我终于明白了!!
with pipeline.InOrder():
yield pipelines.Log2Bq()
yield pipelines.YourOtherPipeline()