Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does Azure Function Python V2 supports multiple functions in a single Function Apps #1395

Closed
twsh15 opened this issue Jan 11, 2024 · 1 comment

Comments

@twsh15
Copy link

twsh15 commented Jan 11, 2024

Hi all,

I need help setting up a project structure for my scenario - 3 different functions deployed in a single Azure Functions App. As far as I know, the only way to do so is to put all code logic of 3 functions as well as triggers in a single function_app.py, which is impractical from code maintainability and scalability perspectives. Something like the one below will work, but I don't think I'd go with it.

app = func.FunctionApp()

@app.schedule(schedule="0 0 2 * * *", arg_name="myTimer", run_on_startup=True,
              use_monitor=False) 
def FunctionA(myTimer: func.TimerRequest) -> None:
     do_something_for_functionA()
    if myTimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function executed.')

@app.schedule(schedule="0 0 2 * * *", arg_name="myTimer", run_on_startup=True,
              use_monitor=False) 
def FunctionB(myTimer: func.TimerRequest) -> None:
    do_something_for_functionB()
    if myTimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function executed.')

@app.schedule(schedule="0 0 2 * * *", arg_name="myTimer", run_on_startup=True,
              use_monitor=False) 
def FunctionC(myTimer: func.TimerRequest) -> None:
    do_something_for_functionC()
    if myTimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function executed.')

I need something more management and organized like below one (if possible):

.
└── Functions/
    ├── .venv
    ├── .python_packages
    ├── .vscode
    ├── .funcignore
    ├── .gitignore
    ├── function_app.py
    ├── function_a.py
    ├── function_b.py
    ├── function_c.py
    ├── host.json
    ├── local.settings.json
    └── requirements.txt
@gavin-aguiar
Copy link
Contributor

@tswh15 You can use blueprints to separate out functions in different files. You would only need to register them in the function_app.py file
Here is more information on how to use blueprints.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-decorators#blueprints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants