简体   繁体   English

使用 HttpSensor 触发气流 DAG

[英]Trigger Airflow DAG using HttpSensor

I'm trying to implement the exact use case as mentioned here , but I'm having issues.我正在尝试实现这里提到的确切用例,但我遇到了问题。 I can't seem to actually set the trigger off in order to execute task t1 , even though I'm changing the google sheet referenced.我似乎无法实际设置触发器以执行任务t1 ,即使我正在更改引用的谷歌表。 I've made sure all path references are right and I have access to the necessary APIs (google drive).我已经确保所有路径引用都是正确的,并且我可以访问必要的 API(谷歌驱动器)。 I'm very new to Airflow, so I suspect I'm missing fundamental in my dag:我对 Airflow 很陌生,所以我怀疑我的 dag 中缺少基础知识:

from airflow import DAG
from airflow.sensors.http_sensor import HttpSensor
from airflow.operators.bash_operator import BashOperator
from airflow.contrib.operators.bigquery_operator import BigQueryOperator
from datetime import timedelta, datetime

args = {
    'owner': 'airflow',
    'depends_on_past': False, 
    'start_date': datetime(2020, 11, 23),
    'email': 'my_email@gmail.com',
    'email_on_failure': True,
}

dag = DAG(
    'my_dag',
    default_args=args,
    description='blah blah',
    schedule_interval='*/5 * * * *'
)

# sensor to detect changes in google sheet
s = HttpSensor(
    task_id='check_sheet_change',
    http_conn_id='http_default',
   endpoint='https://www.googleapis.com/drive/v3/files/hiddenfromyouid',
    request_params={},
    response_check=lambda response: response.json()['modifiedTime'] > (datetime.now() - timedelta(seconds=30)),
    poke_interval=30,
    dag=dag,
)

# if s is triggered, do stuff in python
t1 = BashOperator(
    task_id='do stuff in python',
    bash_command='python3 /home/airflow/gcs/dags/pythons/mypyfile.py',
    dag=dag
)

s >> t1

What am I missing?我错过了什么? Any help is appreciated.任何帮助表示赞赏。

endpoint of HttpSensor is for relative part of URL. HttpSensor endpoint用于 URL 的相对部分。

try this, and http_default connection should direct https://www.googleapis.com试试这个, http_default连接应该http_default https://www.googleapis.com

s = HttpSensor(
    task_id='check_sheet_change',
    http_conn_id='http_default',
   endpoint='/drive/v3/files/hiddenfromyouid',
    request_params={},
    response_check=lambda response: response.json()['modifiedTime'] > (datetime.now() - timedelta(seconds=30)),
    poke_interval=30,
    dag=dag,
)



声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM