I have the requirement to execute an Azure Function (let’s call it OperationalFunction) only once in parallel. What I mean is the following:
I have two “entry point” functions:
I have a BlobTrigger Function (BlobTriggeredStartFunction)
I have a HttpTrigger Function (HttpTriggeredStartFunction)
Both of those functions call an orchestrator function (OrchestratorFunction) like this:
string instanceId = await starter.StartNewAsync(nameof(OrchestrationFunction),null,data);
This orchestration function has the following code:
[FunctionName("OrchestrationFunction")]
public async Task OrchestrationFunction(
[OrchestrationTrigger] IDurableOrchestrationContext context){
var input = context.GetInput<string>();
await context.CallActivityAsync(nameof(OperationalFunction),input);
}
I want that the *OperationalFunction *is executed ONLY ONCE in parallel, so that if I receive multiple triggers (n blob/http-triggered events), the *OperationalFunction *at a certain time, is executing only one instance, when such instance finishes, then the new event in the queue (FIFO) is executed.
Which is the best approach to that?
I tried to edit the host.json file by adding:
"blobs": {
"maxDegreeOfParallelism": 1,
"poisonBlobThreshold": 1
}
But it is not exactly what I am looking for, just a part of the problem is solved.
I also tried to add a loop do…while for getting the status of the orchestrator:
do {
status = await starter.GetStatusAsync(instanceId);
await Task.Delay(2000);
}
while (
status.RuntimeStatus == OrchestrationRuntimeStatus.Running ||
status.RuntimeStatus == OrchestrationRuntimeStatus.Pending);
But I don’t think this is the most efficient solution.
RB_D4S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1