C#
I want to use the CancellationToken to safely perform the restart that takes place during the execution of the Function.
I wrote the following code and tried the behavior of CancellationToken, but it seemed that cancellation was not performed when Function Host shutdown.
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
CancellationToken cancellationToken,
ILogger log)
{
log.LogInformation("C# HTTP trigger function start.");
try
{
// simulate excessive cpu time process
await Task.Delay(TimeSpan.FromSeconds(30), cancellationToken);
}
catch (OperationCanceledException)
{
log.LogInformation("C# HTTP trigger function canceled.");
return new BadRequestResult();
}
log.LogInformation("C# HTTP trigger function end.");
return new OkResult();
}
}
The following is the log when trying to restart from Azure Portal while Function is running.

It seems that forced shutdown is performed while executing Function. Not only restart but also deployment has the same result.
On the other hand, at Function Timeout, it was confirmed that CancellationToken was working.

Is there a way to run Graceful shutdown like WebJobs?
@alrod - can you help answer this question?
@shibayan the approach you're using is correct. We do depend on the shutdown signaling flowing from IIS so we can correctly signal that token, and that should be happening in that scenario.
Assigning this for investigation as it looks like a defect.