amoghrajesh commented on PR #48683:
URL: https://github.com/apache/airflow/pull/48683#issuecomment-2774613123

   Added more tasks in the task to test for shortcircuit and sensor too.
   
   DAG:
   ```
   import sys
   import tempfile
   
   from airflow.decorators import dag, task
   from airflow.providers.standard.operators.empty import EmptyOperator
   
   
   @dag()
   def all_decorators():
       # python
       @task
       def python():
           return "Hello!"
   
       python()
   
       # bash
       @task.bash
       def bash() -> str:
           return "echo https://airflow.apache.org/";
   
       bash()
   
       # external-python
       @task.external_python(python=sys.executable)
       def external_python():
           print("doing something in external Python")
   
       external_python()
   
       empty_task_1 = EmptyOperator(task_id="empty_task_1")
       empty_task_2 = EmptyOperator(task_id="empty_task_2")
   
       # branch
       @task.branch()
       def branch_task(**kwargs) -> str:
           """
           Determine which empty_task should be run based on if the logical 
date minute is even or odd.
   
           :param dict kwargs: Context
           :return: Id of the task to run
           """
           return "empty_task_2"
       cond = branch_task()
       cond >> [empty_task_1, empty_task_2]
   
       venv_a = EmptyOperator(task_id="venv_a")
       venv_b = EmptyOperator(task_id="venv_b")
       venv_c = EmptyOperator(task_id="venv_c")
       venv_d = EmptyOperator(task_id="venv_d")
   
       # branch virtual env
       @task.branch_virtualenv(requirements=["numpy~=1.26.0"], 
venv_cache_path=tempfile.gettempdir())
       def branching_virtualenv(choices) -> str:
           import random
   
           import numpy as np
   
           print(f"Some numpy stuff: {np.arange(6)}")
           return f"venv_{random.choice(choices)}"
   
       options = ["a", "b", "c", "d"]
       branching_virtualenv(choices=options)
   
       # external_python
       @task.external_python(python=sys.executable)
       def external_python():
           print("doing something in external Python")
   
       external_python()
   
       @task.short_circuit()
       def short_circuit():
           return True
   
       @task.virtualenv(
           requirements=["numpy~=1.26.0"], venv_cache_path=tempfile.gettempdir()
       )
       def virtualenv():
           import numpy as np
   
           print(f"Some numpy stuff: {np.arange(6)}")
   
       short_circuit() >> virtualenv()
   
   all_decorators()
   
   ```
   
   
![all_decorators-graph](https://github.com/user-attachments/assets/a004d948-ac02-4cae-9f0c-ed1907e3c1eb)
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to