Appengine管道,如何让函数在管道工作完成后立即执行

2024-09-30 14:21:17 发布

您现在位置:Python中文网/ 问答频道 /正文

https://code.google.com/p/appengine-pipeline/wiki/GettingStarted#Execution_ordering

我试图添加一个回调函数,在Log2Bq完成后执行。 但不管我用pipeline.After还是pipeline.InOrder,它都不起作用。在下面的代码示例中,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())
                }
            )

Tags: httpscomdatepipelinegooglewikicodetrack
1条回答
网友
1楼 · 发布于 2024-09-30 14:21:17

pipeline.InOrder()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())
            }
         )

如果你想用管道订单()或管道。之后()您应该将任务队列代码包装在其他管道中,并在pipelines.Log2Bq()之后生成它

^{pr2}$

相关问题 更多 >