0

I defined a DAG which has two params date_start and date_end, which can be manually informed when DAG is manually triggered using config. Given this dates, before passing them to triggered DAGs, I want to verify if they have the correct format and if they were informed or not. Is it possible to do it without creating a task? So, would it be possible to use a DAG param outside a task, but inside the DAG definition?

Here is my code:

# Define the DAG object
@dag(default_args=default_args, catchup=False,
     dagrun_timeout=timedelta(seconds=3600), doc_md=DOC_MD, max_active_runs=1)
def main_dag(date_start=None, date_end=None):

     # passing params to triggered dags only if parms are given
     date_format = "%Y-%m-%d"
     try:
          res = bool(datetime.strptime(date_start, format))
     except:
          res = False 

     if res:
          conf = {"date_start": '{{params.date_start}}', "date_end": '{{params.date_end}}'}
     else:
          conf = {}

     triggered_dag = TriggerDagRunOperator(
          task_id='triggered_dag ',
          trigger_dag_id='triggered_dag ',
          # trigger_rule=TriggerRule.ALL_SUCCESS,
          wait_for_completion=True,
          poke_interval=30,
          conf=conf
     )

This code is not working, the workaround I've found is creating a task and the giving conf to triggered_dag with xcom pull.

Thanks in advance.

Cristian Ispan
  • 571
  • 2
  • 5
  • 23

0 Answers0