【发布时间】:2020-08-13 09:01:44
【问题描述】:
我有一个批处理作业在数据流运行器上的 apache-beam[gcp]==2.19.0 版本下的 gcp 数据流中运行。我为该工作创建了一个自定义模板。该作业按预期运行,但我还想添加一个最大作业持续时间。 I found the duration (in milliseconds) parameter inside the wait_until_finish() method,which should be available。问题是:如何让模板化批处理作业在运行时间超过持续时间时自动停止?我不需要保留任何数据,我只希望作业在运行时间过长时停止。我已经实现了run函数如下:
def run():
opts = PipelineOptions()
user_options = opts.view_as(UserOptions)
p = beam.Pipeline(options=opts)
(p |
"Read data" >> beam.io.Read(beam.io.BigQuerySource(query=user_options.query,
use_standard_sql=StaticValueProvider(bool, True))) |
"Get data" >> beam.ParDo(doStuff()) |
"Output data" >> beam.ParDo(outputData(param1=user_options.input1)) |
"Write to BQ" >> beam.io.WriteToBigQuery(
table=user_options.table_spec,
schema=user_options.table_schema,
write_disposition=beam.io.BigQueryDisposition.WRITE_TRUNCATE,
create_disposition=beam.io.BigQueryDisposition.CREATE_IF_NEEDED
)
)
result = p.run()
result.wait_until_finish(duration=1800000)
【问题讨论】:
标签: python google-cloud-dataflow apache-beam dataflow