I have a [DurableOrchestrationClient] that starts a [OrchestrationTrigger] that starts a long running [ActivityTrigger] function.
I know how to use TerminateAsync() to Terminate the [OrchestrationTrigger] from running.
The problem is that [ActivityTrigger] is not aborted when I terminate the [OrchestrationTrigger] function. [ActivityTrigger] keeps running until its done.
I need a way to abort the long running [ActivityTrigger] when I call TerminateAsync().
My guess is that I can pass a CancellationToken to [ActivityTrigger] function and then check cancellationToken.IsCancellationRequested to abort.
But how to do this?
Here is a test code
[FunctionName("A_ProcessPayment")]
public static async Task<processTracker> A_ProcessPayment(
[ActivityTrigger] DurableActivityContext context,
TraceWriter log,
CancellationToken cancellationToken)
{
processTracker p = context.GetInput<processTracker>();
try
{
for (int i = 0; i < 5; i++){
if (cancellationToken.IsCancellationRequested) // This is always false!
{
break;
}
Trace.WriteLine("Long task loop: " + i);
await Task.Delay(10000);
}
}
catch (OperationCanceledException) {
log.Warning("C# HTTP trigger function canceled.");
return p;
}
Trace.WriteLine("Long task DONE");
return p;
}