I has been using a suggested Microsoft approach, that use IHostedService for provide to the web app the availability of enqueue background jobs. The idea consists in use a ConcurrentQueue of tasks, in order to push tasks to this queue, and an IHostedService try to pull from the queue and execute the task.
I used this approach in several microservices, locally all runs perfectly, and the job execution start immediately after the POST operation that is responsible in the push operation to concurrent queue.
But, when all those microservices are published on kubernetes cluster, I sometimes see delays on the execution of the job, and I don't have any idea about why.
The delays are faced after the pop operation from the queue, specifycally when the program execute the instruction
await t;
and t, is the task poped from the queue.
Any suggestion?