气流触发DAG后的任何时候谷歌表正在更新



有没有办法安排DAG在谷歌工作表更新后立即触发?

不确定我是否从这位医生那里得到了答案:https://airflow.readthedocs.io/en/latest/_api/airflow/providers/google/suite/hooks/sheets/index.html

@Alejandro的方向是正确的,但只是扩展到他的答案。您可以使用HttpSensor操作符通过谷歌驱动api 对表单文件进行获取请求

HttpSensor(
task_id='http_sensor_check',
http_conn_id='http_default',
endpoint='https://www.googleapis.com/drive/v3/files/fileId',
request_params={},
response_check=,
poke_interval=5,
dag=dag,
)

现在,根据返回响应文档,它应该返回modeifiedtime,您可以在response_check中的响应中看到

response_check=lambda response: response.json()['modifiedTime'] > last_time_stored

你可以替换这个lambda,并从Db或缓存等中获取值。

触发时间::现在,您可以将next操作符和该传感器结合使用来有条件地触发。

注意:这里poke_Interval取决于用例,以及您希望检查修改的频率。

您可以将HTTPOperator与Google drive API一起使用https://developers.google.com/drive/api/v3/reference/files/get

您也可以编写自己的实现,请参阅WebHDFSHook和WebHDFSSensor以供参考

最新更新