How can in run a dag with one task

Viewed 1569
default_args = {
"owner": "airflow_admin",
"start_date": datetime(2017, 8, 29),
"schedule_interval":'*/5 * * * *'
 }
with DAG(
'my_first_dag',
catchup=False,
default_args=default_args,
) as dag:

   task1 = BashOperator(
   task_id='id1',
   bash_command=bash_.format('db1', 'tab1'))

task1

does anyone knows how to launch a dag with one task please, the code above don't work, the dag is launched properly

2 Answers

Make sure that your indentation is correct. Your task should be defined inside the scope of the DAG context manager, otherwise you must provide the dag parameter to your task:

Try:


default_args = {
    "owner": "airflow_admin",
    "start_date": datetime(2017, 8, 29),
    "schedule_interval": "0 5 * * *"
}
with DAG('my_first_dag', catchup=False, default_args=default_args) as dag:
    task1 = BashOperator(
        task_id='id1',
        bash_command=bash_.format('db1', 'tab1'))

Or without using context manager:

default_args = {
    "owner": "airflow_admin",
    "start_date": datetime(2017, 8, 29),
    "schedule_interval": "0 5 * * *"
}
dag = DAG('my_first_dag', catchup=False, default_args=default_args)
task1 = BashOperator(
        task_id='id1',
        bash_command=bash_.format('db1', 'tab1'),
        dag=dag)

Can you try giving schedule interval as parameter to dag, instead of in default_args?

default_args = {
"owner": "airflow_admin",
"start_date": datetime(2017, 8, 29),
 }
with DAG(
'my_first_dag',
catchup=False,
default_args=default_args,
schedule_interval="*/5 * * * *",
) as dag:

   task1 = BashOperator(
   task_id='id1',
   bash_command=bash_.format('db1', 'tab1'))

Hope this works.

Related