I want to use Python Blob Trigger as a durable function client to trigger an orchestrated process, but I don't see any option for blob trigger in durable function can any one guide me ?
2 Answers
You need to change the __init__.py and function.json files of BlobTrigger as follows:
__init__.py:
import logging
import azure.functions as func
import azure.durable_functions as df
async def main(myblob: func.InputStream, starter: str):
logging.info("Python blob trigger function processed blob)
client = df.DurableOrchestrationClient(starter)
instance_id = await client.start_new('YourNewDurableFunction')
function.json:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "ContainerName/{name}",
"connection": "AZURE_STORAGE_CONNECTION_STRING"
},
{
"name": "starter",
"type": "durableClient",
"direction": "in"
}
]
}
Comments
If you want to use Python Blob Trigger as a durable function client to trigger an orchestrated process, you need two functions:
- One for durable function (orchestrator) itself
- Another for the Blob trigger.
Make use of below script to create blob trigger function:
[FunctionName("StartOrchestratorBlobTrigger")]
public async Task StartOrchestratorBlobTrigger(
[BlobTrigger("sample-workitems/{name}", Connection = "CloudSightStorage")]
Stream myBlob,string name,
[OrchestrationClient] DurableOrchestrationClient durableOrchestrationClient,ILogger log)
{
// get your blob content, and desrialize if you need and pass it orchestrator instead of stream as below
await durableOrchestrationClient.StartNewAsync("YourNewDurableFunction", myBlob);
}
In the above function, The OrchestrationTrigger would be used as a trigger for your durable function.
To create durable function, make use of below sample script:
[FunctionName("YourNewDurableFunction")]
public async Task YourNewDurableFunction
(
[OrchestrationTrigger]
DurableOrchestrationContextBase orchestrationContext,ILogger logger)
{
// Call activity functions here.
}
For more information in detail, please refer below links:
Use durable function with blobstorage trigger and i get an error - Microsoft Q&A aakash-sharma answered
Durable Function Blob Trigger - Stack Overflow by Sebastian Achatz