Skip to content

Support setting dependencies for tasks called outside TaskGroup context manager#32351

Merged
ephraimbuddy merged 6 commits into
apache:mainfrom
astronomer:improve-taskgroup-ctx
Jul 14, 2023
Merged

Support setting dependencies for tasks called outside TaskGroup context manager#32351
ephraimbuddy merged 6 commits into
apache:mainfrom
astronomer:improve-taskgroup-ctx

Conversation

@ephraimbuddy
Copy link
Copy Markdown
Contributor

@ephraimbuddy ephraimbuddy commented Jul 4, 2023

Currently, you must instantiate a classic operator or call a decorated operator inside the context manager before it will link up with the context manager. For example, tasks 1 and 2 below will be outside the group1 context:

   task1 = BashOperator(task_id="task1", bash_command="echo task1")
   task2 = BashOperator(task_id="task2", bash_command="echo task2")
   with TaskGroup('group1'):
        task1 >> task2

This PR addresses the above such that when you do that, the tasks will be inside the group1 context.
For a single task, you can do:

   task1 = BashOperator(task_id="task1", bash_command="echo task1")
   with TaskGroup('group1') as scope:
        scope.add_task(task1)

@ephraimbuddy ephraimbuddy force-pushed the improve-taskgroup-ctx branch 2 times, most recently from 50a8ca9 to 001b8ae Compare July 5, 2023 07:57
@ephraimbuddy ephraimbuddy marked this pull request as ready for review July 5, 2023 07:58
Comment thread airflow/models/taskmixin.py Outdated
Comment thread airflow/utils/task_group.py Outdated
@ephraimbuddy ephraimbuddy force-pushed the improve-taskgroup-ctx branch 3 times, most recently from 3b00407 to 8b129b4 Compare July 10, 2023 16:09
Comment thread airflow/utils/task_group.py Outdated
Comment thread airflow/utils/task_group.py Outdated
@ephraimbuddy ephraimbuddy requested a review from uranusjr July 12, 2023 20:44
@ephraimbuddy ephraimbuddy force-pushed the improve-taskgroup-ctx branch 3 times, most recently from d4d402a to ac2aa9e Compare July 12, 2023 21:46
Comment thread airflow/models/taskmixin.py Outdated
Comment thread airflow/models/taskmixin.py Outdated
Comment thread airflow/models/taskmixin.py Outdated
@ephraimbuddy ephraimbuddy force-pushed the improve-taskgroup-ctx branch from 88759ef to ec2a74c Compare July 13, 2023 10:36
Comment thread airflow/models/taskmixin.py Outdated
…xt manager

Currently, you must instantiate a classic operator or call a decorated
operator inside the context manager before it will link up with the context manager.
For example, tasks 1 and 2 below will be outside the group1 context:
```
   task1 = BashOperator(task_id="task1", bash_command="echo task1")
   task2 = BashOperator(task_id="task2", bash_command="echo task2")
   with TaskGroup('group1'):
        task1 >> task2
```
This PR addresses the above such that when you do that, the tasks will
be inside the group1 context.
For a single task, you can do:
```
   task1 = BashOperator(task_id="task1", bash_command="echo task1")
   with TaskGroup('group1') as scope:
        scope.add(task1)
```
@ephraimbuddy ephraimbuddy force-pushed the improve-taskgroup-ctx branch from 40c843b to 92dcac3 Compare July 14, 2023 13:57
@ephraimbuddy ephraimbuddy merged commit 1a1753c into apache:main Jul 14, 2023
@ephraimbuddy ephraimbuddy deleted the improve-taskgroup-ctx branch July 14, 2023 15:44
@ephraimbuddy ephraimbuddy added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label Aug 2, 2023
@ephraimbuddy ephraimbuddy added this to the Airflow 2.7.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..)

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

2 participants