Execute azure durable function activities in raised order

123 views Asked by At

How can we ensure that the "activities" of an "Azure Durable Function" are executed in a specific order?

Let's say we start 3 different instances of the orchestrator:

StartNewAsync("myOrchestrator", 11111111-1111-1111-1111-111111111111)
StartNewAsync("myOrchestrator", 22222222-2222-2222-2222-222222222222)
StartNewAsync("myOrchestrator", 33333333-3333-3333-3333-333333333333)

Later I raise an event on each orchestator instance:

RaiseEventAsync(11111111-1111-1111-1111-111111111111, "sayHello", "1")
RaiseEventAsync(22222222-2222-2222-2222-222222222222, "sayHello", "2")
RaiseEventAsync(33333333-3333-3333-3333-333333333333, "sayHello", "3")

Since there are 3 Orchestrator instances, the execution-order of the "Activities" may change:

"Hello 2"
"Hello 3"
"Hello 1"

Is there a way to ensure that my Acitivities are executed in the same order, I call the RaiseEventAsync?

Probably in this simple example we should use only 1 Orchestrator instance. But in our real use case we need several instances because they differ even more.

I am new to "durable functions". Please tell me if my question does not make sense.

1

There are 1 answers

0
Templar_VII On

I have simply fixed it by add a delay between the RaiseEvent. I know that's not a nice solution, but it works and it doesn't make it even more complicated.

await RaiseEventAsync(11111111-1111-1111-1111-111111111111, "sayHello", "1")
await Task.Dealy(1000);
await RaiseEventAsync(22222222-2222-2222-2222-222222222222, "sayHello", "2");
await Task.Dealy(1000);
await RaiseEventAsync(33333333-3333-3333-3333-333333333333, "sayHello", "3");