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

时间:2013-06-10 05:26:21

标签: python google-app-engine pipeline

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

我尝试添加一个在Log2Bq完成后执行的回调函数。 但是,我使用pipeline.Afterpipeline.InOrder并不起作用。在以下代码示例中,taskqueue将立即执行而无需等待Log2Bq。要解决这个问题, 我是否需要创建另一个管道来保存任务队列以使执行顺序有效?

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())
                }
            )

1 个答案:

答案 0 :(得分:2)

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())
            }
         )

如果你想使用pipeline.InOrder()或pipeline.After(),你应该将你的任务队列代码包装在其他管道中并在pipelines.Log2Bq()

之后产生它
with pipeline.InOrder():
      yield pipelines.Log2Bq()
      yield pipelines.YourOtherPipeline()