2017-04-11 7 views
2

우리는 공기 흐름 UI에서 "그래프보기"에서 dagrun을 수행 할 때 각 작업 실행에 대한 세부 정보를 얻습니다.공기 흐름 검댕이에 대한 작업 ID를 얻는 방법은 무엇입니까?

작업 ID는 "scheduled__2017-04-11T10 : 47 : 00"과 같습니다.

추적/로그 생성을 위해이 작업 ID가 필요합니다.이 작업 ID는 각 작업/dagrun이 수행 한 시간을 유지합니다.

그래서 내 질문은 입니다.을 실행중인 동일한 dag 내에서 작업 ID를 얻는 방법은 무엇입니까?

감사합니다, Chetan에

답변

2

이 값은 실제로 run_id라고하고 상황에 맞는 또는 매크로를 통해 액세스 할 수 있습니다.

이것은 파이썬 연산자에서 컨텍스트를 통해 액세스 할 수 있으며 bash 연산자에서 bash_command 필드의 jinja 템플릿을 통해 액세스 할 수 있습니다.

더 많은 매크로에서 사용할 수 무엇에 대한 정보 : 신사에

https://airflow.incubator.apache.org/code.html#macros

상세 정보 :

https://airflow.incubator.apache.org/concepts.html#jinja-templating

from airflow.models import DAG 
from datetime import datetime 
from airflow.operators.bash_operator import BashOperator 
from airflow.operators.python_operator import PythonOperator 


dag = DAG(
    dag_id='run_id', 
    schedule_interval=None, 
    start_date=datetime(2017, 2, 26) 
) 

def my_func(**kwargs): 
    context = kwargs 
    print(context['dag_run'].run_id) 

t1 = PythonOperator(
    task_id='python_run_id', 
    python_callable=my_func, 
    provide_context=True, 
    dag=dag 
    ) 

t2 = BashOperator(
    task_id='bash_run_id', 
    bash_command='echo {{run_id}}', 
    dag=dag) 

t1.set_downstream(t2) 

사용 예를 들어이 DAG 등에 대한 로그를 확인 각 운영자는 로그에 run_id이 나타나야합니다.

관련 문제