-
I have a requirement where I need to "monitor" some instance for some time after it is created, and to stop monitoring it once the instance is deleted. For now, my application raises EventGrid events on creation and deletion of entities, and I listen to those in my orchestration trigger activity: once a creation event is received, I start the orchestration that monitors that instance. Once the deletion event is received, I send an external event to the orchestrator to signal that it should stop monitoring that instance and terminate. Each creation/deletion pair is handled by its own monitor of course (they are isolated from one another, controlled by an explicit instance ID based on the entity ID). The orchestrator logic basically fires 2 tasks and waits for the first to finish:
If task 2 wins, I cancel the timer (as per the recommendation), and exit the function. If task 1 wins, I do the processing I need on the instance and ignore the external event. The question then becomes: instead of sending an external event and waiting for that to terminate the orchestration, would it be safe to just call Terminate directly on it from the trigger? This would simplify my logic a bit since I wouldn't need to care about any external events in the orchestration, but I'm not sure if terminating the execution is safe when dealing with durable timers (I couldn't find any info on that). Would terminating the instance also terminate the timers in a graceful manner, even though they are currently tied to my own cancellation token source? Would this approach change function usage/costs in any way? Or should I keep my ExternalEvent approach to explicitly cancel execution? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Posted on SO since this didn't get any traction: |
Beta Was this translation helpful? Give feedback.
-
Yes, it's safe to terminate an orchestration, even if it has pending timers outstanding (or pending activity or sub-orchestration calls, for that matter). The orchestration will always transition into the "Terminated" state. Any messages that appear for an instance after it has been terminated (including timer messages) will be silently discarded. |
Beta Was this translation helpful? Give feedback.
Yes, it's safe to terminate an orchestration, even if it has pending timers outstanding (or pending activity or sub-orchestration calls, for that matter). The orchestration will always transition into the "Terminated" state. Any messages that appear for an instance after it has been terminated (including timer messages) will be silently discarded.