Skip to content

Support @task.bash with Task SDK - #48060

Merged
kaxil merged 1 commit into
apache:mainfrom
astronomer:bash-task-decorator
Mar 21, 2025
Merged

kaxil merged 1 commit into
apache:mainfrom
astronomer:bash-task-decorator

Conversation

@kaxil

@kaxil kaxil commented Mar 21, 2025 •

Copy link
Copy Markdown
Member

closes #48046 closes #45639

image

Tried with:

from __future__ import annotations

import pendulum

from airflow.decorators import dag, task


@dag(schedule=None, start_date=pendulum.datetime(2023, 1, 1, tz="UTC"), catchup=False)
def simple_bash_decorator():
    @task.bash
    def run_me(sleep_seconds: int, task_instance_key_str: str) -> str:
        return f"echo {task_instance_key_str} && sleep {sleep_seconds}"

    @task.bash
    def also_run_this() -> str:
        return 'echo "ti_key={{ task_instance_key_str }}"'

    run_me_loop = run_me(sleep_seconds=1)
    run_me_loop >> also_run_this()


simple_bash_decorator()

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@amoghrajesh amoghrajesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the way this has been approached! Thanks!

Comment thread task-sdk/src/airflow/sdk/definitions/baseoperator.py
@kaxil
kaxil force-pushed the bash-task-decorator branch from e3a1c8b to 7f70e99 Compare March 21, 2025 16:47
@kaxil
kaxil requested a review from potiuk as a code owner March 21, 2025 16:47
@kaxil
kaxil force-pushed the bash-task-decorator branch from 7f70e99 to 31b576d Compare March 21, 2025 17:13
@kaxil
kaxil merged commit 8f1a538 into apache:main Mar 21, 2025
@kaxil
kaxil deleted the bash-task-decorator branch March 21, 2025 18:58
agupta01 pushed a commit to agupta01/airflow that referenced this pull request Mar 21, 2025
shubham-pyc pushed a commit to shubham-pyc/airflow that referenced this pull request Mar 22, 2025
aaron-y-chen pushed a commit to aaron-y-chen/airflow that referenced this pull request Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support @task.bash with Task SDK

2 participants