Untitled
unknown
plain_text
2 years ago
923 B
5
Indexable
from airflow import DAG from airflow.operators.python import PythonOperator def add_numbers(**kwargs): """ Function to add two numbers Args: kwargs (dict): Keyword arguments containing DAG run parameters """ num1 = kwargs["conf"].get("num1", None) num2 = kwargs["conf"].get("num2", None) if num1 is None or num2 is None: raise ValueError("Missing parameters: num1 and num2 are required") result = num1 + num2 print(f"The sum of {num1} and {num2} is: {result}") with DAG( dag_id="addition_dag", start_date=datetime(2023, 12, 12), schedule_interval=None, ) as dag: task = PythonOperator( task_id="add_task", python_callable=add_numbers, provide_context=True, ) # Example of triggering the DAG with specific parameters dag_run = dag.create_dagrun( start_date=datetime(2023, 12, 13), conf={"num1": 5, "num2": 10}, )
Editor is loading...
Leave a Comment