Skip to content

Instantly share code, notes, and snippets.

@sakethramanujam
Last active January 6, 2022 16:09
Show Gist options
  • Save sakethramanujam/7c21497dbd11d9b7d93b57c437d2c4dd to your computer and use it in GitHub Desktop.
Save sakethramanujam/7c21497dbd11d9b7d93b57c437d2c4dd to your computer and use it in GitHub Desktop.
Sample Dag with Bash Operator.
#!/usr/bin/python3
from airflow.models import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
# let's setup arguments for our dag
my_dag_id = "my_first_dag"
default_args = {
'owner': 'proton',
'depends_on_past': False,
'retries': 10,
'concurrency': 1
}
# dag declaration
dag = DAG(
dag_id=my_dag_id,
default_args=default_args,
start_date=datetime(2019, 6, 17),
schedule_interval=timedelta(seconds=5)
)
# Here's a task based on Bash Operator!
bash_task = BashOperator(task_id='bash_task_1',
bash_command="echo 'Hello Airflow!'",
dag=dag)
from airflow.models import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime, timedelta
my_dag_id = "my_first_dag"
default_args = {
'owner': 'proton',
'depends_on_past': False,
'retries': 10,
'concurrency': 1
}
def hello():
print("Hello Airflow Using a Python Operator!")
dag = DAG(
dag_id=my_dag_id,
default_args=default_args,
start_date=datetime(2019, 6, 17),
schedule_interval=timedelta(minutes=5)
)
python_task = PythonOperator(task_id='python-task',
python_callable=hello,
dag=dag)
from airflow.models import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime, timedelta
my_dag_id = "my_first_python_dag_with_kwargs"
default_args = {
'owner': 'proton',
'depends_on_past': False,
'retries': 10,
'concurrency': 1
}
def my_args(*args,**kwargs):
print("My Args are {}".format(args))
print("My Kwargs are {}".format(kwargs))
dag = DAG(
dag_id=my_dag_id,
default_args=default_args,
start_date=datetime(2019, 6, 17),
schedule_interval=timedelta(seconds=5)
)
python_task = PythonOperator(task_id='python-task',
python_callable=my_args,
op_args={'a','b','c'},
op_kwargs={'a':'2'},
dag=dag)
from airflow.models import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime, timedelta
my_dag_id = "my_first_python_dag_with_args"
default_args = {
'owner': 'proton',
'depends_on_past': False,
'retries': 10,
'concurrency': 1
}
def my_args(*args):
print("My Args are {}".format(args))
dag = DAG(
dag_id=my_dag_id,
default_args=default_args,
start_date=datetime(2019, 6, 17),
schedule_interval=timedelta(seconds=5)
)
python_task = PythonOperator(task_id='python-task',
python_callable=my_args,
op_args={'a','b','c'},
dag=dag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment