Created
July 2, 2021 07:47
-
-
Save MachineLearningIsEasy/c0fd6b24b938ed82e560a1fcf90c1ed4 to your computer and use it in GitHub Desktop.
Airflow DAG with PythonVirtualenvOperator Task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
from airflow import DAG | |
from airflow.operators.bash_operator import BashOperator | |
from airflow.operators.docker_operator import DockerOperator | |
from airflow.operators.python_operator import BranchPythonOperator, PythonOperator, PythonVirtualenvOperator | |
from airflow.operators.dummy_operator import DummyOperator | |
import os | |
default_args = { | |
'owner' : 'dimon', | |
'description' : 'Use of the PythonVirtualenvOperator', | |
'depend_on_past' : False, | |
'start_date' : datetime(2021, 5, 1), | |
'email_on_failure' : False, | |
'email_on_retry' : False, | |
'retries' : 1, | |
'retry_delay' : timedelta(minutes=5) | |
} | |
def callable_virtualenv(): | |
import catboost | |
return catboost.__version__ | |
with DAG('docker_operator_dag', default_args=default_args, schedule_interval="5 * * * *", catchup=False) as dag: | |
start_dag = DummyOperator( | |
task_id='start_dag' | |
) | |
end_dag = DummyOperator( | |
task_id='end_dag' | |
) | |
t1 = BashOperator( | |
task_id='print_current_date', | |
bash_command='date' | |
) | |
t2 = PythonVirtualenvOperator( | |
task_id="second_task", | |
python_callable=callable_virtualenv, | |
requirements=["catboost==0.25.0"], | |
provide_context=True, | |
system_site_packages=True, | |
) | |
t3 = PythonVirtualenvOperator( | |
task_id="third_task", | |
python_callable=callable_virtualenv, | |
requirements=["catboost==0.26.0"], | |
provide_context=True, | |
system_site_packages=True, | |
) | |
t4 = BashOperator( | |
task_id='print_hello', | |
bash_command='echo "hello world"' | |
) | |
start_dag >> t1 | |
t1 >> t2 >> t4 | |
t1 >> t3 >> t4 | |
t4 >> end_dag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment