Hi @Gaia Dennison ,
I have used below code and approach which works for me:
Structure:
project-root/
│
├── __pycache__/
├── .venv/
├── .vscode/
├── .funcignore
├── .gitignore
├── function_app.py
├── host.json
├── local.settings.json
├── requirements.txt
├── testchain.py
function_app.py:
import azure.functions as func
import azure.durable_functions
from testchain import cho
rith = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
rith.register_blueprint(cho)
Used register_blueprint
in registering it.
testchain. py:
import logging as ri_lg
import azure.functions as func
import azure.durable_functions as df
import json
cho = df.Blueprint()
@cho.route(route="startOrchestrator")
@cho.durable_client_input(client_name="client")
async def start_orchestrator(req: func.HttpRequest, client):
instance_id = await client.start_new("my_orchestrator")
ri_lg.info(f"Hello Rithwik, Started orchestration with ID = '{instance_id}'.")
return client.create_check_status_response(req, instance_id)
@cho.orchestration_trigger(context_name="context", orchestration="my_orchestrator")
def my_orchestrator(context: df.DurableOrchestrationContext):
result1 = yield context.call_activity('rith_cho', 'rith_cho_1')
result2 = yield context.call_activity('rith_cho', 'rith_cho_2')
return [result1, result2]
@cho.activity_trigger(input_name="rb")
@cho.sql_input(arg_name="rbch", command_text="SELECT * FROM [dbo].[test]", command_type="Text", parameters="@LOT={rb}", connection_string_setting="Testcon")
def rith_cho(rb: str, rbch: func.SqlRowList) -> list:
rows = list(map(lambda r: json.loads(r.to_json()), rbch))
return rows
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=rithwik953b;AccountKey=JDfotYrithwikchotuwQ==;EndpointSuffix=core.windows.net",
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"Testcon":"Server=tcp:rithwik.database.windows.net,1433;Initial Catalog=test1;Persist Security Info=False;User ID=rithwik;Password=password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
"PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1"
}
}
host.json:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
In SQL :
Output:
Try to follow correct structure and give correct connection string value, it will work as it worked for me.
If this answer was helpful, please click "Accept the answer" and mark Yes
, as this can help other community members.
If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.