I'm using an Azure Function Elastic Premium to perform long running operations involving subscriptions to several Azure ServiceBus topics. The Function plan can scale up to 4 instances at most, each of them is having its own connection to service bus topics. When the long running operation is done the Azure Function instances are discarded as expected but I cannot find a way to intercept that event to shutdown active service bus subscriptions, leaving them active and ever-growing...
Is there a way I can subscribe to a "function app shuting down" event to clean everything properly ?
BTW my service bus subscription are kept in a IDisposable Singleton registered with DI but Dispose() is not called in that scenario unfortunately...