admin管理员组

文章数量:1296391

I have a helper function need to run in every task to init environment.

The problem is, task can not access any variable out of it self's scope. So I have to add the same code to the beginning of every task, like:

@task.external_python(
    python=v_python_path,
    retries=3,
)
def init_env():
    ### this part have to be added for every task
    import sys

    sys.path.append("/opt/airflow/dags")
    ####

    from my_module import my_function

Is there a way to make it cleaner and graceful?

本文标签: