使用参数在Google Cloud Conductor中触发DAG

时间:2018-08-16 15:58:37

标签: google-cloud-platform google-cloud-functions airflow

https://cloud.google.com/composer/docs/how-to/using/triggering-with-gcf示例中,它允许您基于事件触发名称触发dag。您还可以将事件中的参数传递给dag吗,例如添加到存储桶中的文件名?

1 个答案:

答案 0 :(得分:1)

我确实能够使用参数从Cloud Functions触发DAG。 为此,我使用了Rest API Plugin made by robertsanders

我必须将JSON映射作为参数传递给WEBSERVER_URL:

const WEBSERVER_URL = 'https://' + WEBSERVER_ID + '.appspot.com/admin/rest_api/api?api=trigger_dag&dag_id=' + DAG_NAME + '&conf=%7B%22fileName%22%3A%22' + fileName + '%22%7D';

然后,在PythonOperator中,我能够像这样获得地图的fileName条目:

def get_file_name_from_trigger(ds, **kwargs):
    return kwargs['dag_run'].conf['fileName']