I have a use case which requires me to fire some Azure Durable Functions without caring about its results, and I was wondering if my approach is the correct one.
This is the scenario I'm in:
- Function
A
uses anHttpTrigger
- Function
B
uses anActivityTrigger
This is my workflow:
A
is invoked and needs to do some business logic- Alongside this business logic, I need to do a long background task that may or may not fail. I don't care about the results, but I need to run this task everytime
A
is invoked. A
needs to return as quick as possible, that's why I can't wait for the background task to finishB
takes care of this background task whileA
returns
All the Durable Functions examples that I'm finding online show something like this:
await starter.StartNewAsync("BackgroundDurableFunction", data)
My issue is here is that I don't want to await
the Durable Function but I need it to just run in background and do its things (mostly network I/O).
To avoid waiting for this Durable Function I ended up with this workaround:
Task.Factory.StartNew(() => starter.StartNewAsync("BackgroundDurableFunction", data));
This seems to work just right, as I don't need to await
anything, but after reading The Dangers of Task.Factory.StartNew I'm a little bit scared that this might be a dangerous solution.
So, the question is: what's the correct way to start a Durable Function and have it run in background without caring about its results (and without having warnings about not waiting for the task)?