I just took over a project and one of the functional requirements is to call a function every 10 minutes. I found the following code
async Task Run(CancellationToken cancel)
{
while (!cancel.IsCancellationRequested)
{
await DoSomething(cancel);
await Task.Delay(TimeSpan.FromMinutes(10), cancel);
}
}
However, I found the application is deployed to Kubernetes with multiple instances (replicaCount > 1). The logs show the function is called twice every 10 minutes when replicaCount == 2.
How to make sure the function is called once by multiple containers?