0

I have created 2 Python (V2 Programming model) Azure Functions in Vs Code and used a workspace. When I click F5 or start debugging, only the first project session starts debugging, but not the second. When I use func start in terminal for second project, it starts the project but I need to debug rather than just run. Following are my configuration files -

Launch.json

{
    "configurations": [
        {
            "name": "Attach to Preferences",
            "type": "python",
            "request": "attach",
            "port": 9091,
            "preLaunchTask": "func: host start",
            "project": "${workspaceFolder}/API.Preferences"
        },
        {
            "name": "Attach to Charts",
            "type": "python",
            "request": "attach",
            "port": 7071,
            "preLaunchTask": "func: host start", 
            "project": "${workspaceFolder}/API.Charts"
        }
    ]
}

Settings.json

{
    "azureFunctions.deploySubpath": ".",
    "azureFunctions.scmDoBuildDuringDeployment": true,
    "azureFunctions.pythonVenv": ".venv",
    "azureFunctions.projectLanguage": "Python",
    "azureFunctions.projectRuntime": "~4",
    "debug.internalConsoleOptions": "neverOpen",
    "azureFunctions.projectLanguageModel": 2,
    "azureFunctions.projectSubpath": "API.Charts"
}

Tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "func",
            "label": "func: host start",
            "command": "host start",
            "problemMatcher": "$func-python-watch",
            "isBackground": true,
            "dependsOn": "pip install (functions)",
            "options": {
                "cwd": "${workspaceFolder}/API.Preferences"
            }
        },
        {
            "label": "pip install (functions)",
            "type": "shell",
            "osx": {
                "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
            },
            "windows": {
                "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
            },
            "linux": {
                "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
            },
            "problemMatcher": [],
            "options": {
                "cwd": "${workspaceFolder}/API.Preferences"
            }
        }
    ]
}

code.workspace.json file

{
    "folders": [
        {
            "path": ".."
        },
        {
            "path": "../API.Preferences"
        },
        {
            "path": "../API.Charts"
        }
    ],
    "settings": {
        "debug.internalConsoleOptions": "neverOpen"
    },
    "launch": {
        "configurations": [],
        "compounds": [
            {
                "name": "Attach to both apps",
                "configurations": [
                    "Attach to Preferences",
                    "Attach to Charts"
                ]
            }
        ]
    }
}

Any help would be greatly appreciated

1 Answer 1

0

Refer my SO answer here

According to this Microsoft Blog on Function V2 programming model. In order to reduce multiple Folders and File management, You need to add multiple Azure Function triggers in the same function_app.py with multiple output and input bindings

Thus instead of creating separate folders for each Function Trigger, You need to add both the triggers in the same function_app.py file for it to debug together. As, You have created Function project separately in another folder, you need to manually visit the specific Function Project folder root and run func host start to run and debug the individual Function. If you want to keep the Function triggers in separate file you can create blueprint implementation by referring my SO answer here, Where I have referenced 2 of my SO threads for the blueprint and multiple folder implementation.

function_app.py:-

import azure.functions as func
import logging

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.route(route="http_trigger")
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

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

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

I have created Http_trigger then added Timer_trigger in the same file, You can also create separate blueprint file for the same:-

enter image description here

Output:-

I clicked fn + F5 button or F5 and both the Functions got executed together:-

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.