Bashoperator python2

이 예시에서는 Airflow가 스크립트를 DAG로 파싱하지 못하도록 데이터 폴더에서 Python 스크립트를 실행합니다.

코드 샘플

Python

import datetime

from airflow import models
from airflow.operators import bash_operator

yesterday = datetime.datetime.combine(
    datetime.datetime.today() - datetime.timedelta(1),
    datetime.datetime.min.time())

default_dag_args = {
    # Setting start date as yesterday starts the DAG immediately when it is
    # detected in the Cloud Storage bucket.
    'start_date': yesterday,
}

with models.DAG(
        'composer_sample_bashoperator_python2',
        schedule_interval=datetime.timedelta(days=1),
        default_args=default_dag_args) as dag:

    run_python2 = bash_operator.BashOperator(
        task_id='run_python2',
        # This example runs a Python script from the data folder to prevent
        # Airflow from attempting to parse the script as a DAG.
        bash_command='python2 /home/airflow/gcs/data/python2_script.py',
    )

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.