0

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 2

1

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"
    }
  ]
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Bindings for Durable Functions - Azure | Microsoft Docs

2 Comments

Thank you for your reply, but do you have a python script please? it would be perfect.
Please refer this link for python script

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.