I have declared a ConcurrentQueue
and added a list of GUIDs. Adding into the queue is fine, but when I access the queue from inside the TimerTrigger
function it seems like it's empty (updateQueue.count
is 0). This behavior is happening in the cloud, but when I execute the same locally it works fine.
public static class Function1
{
private static readonly ConcurrentQueue<IEnumerable<Guid>> updateQueue = new ConcurrentQueue<IEnumerable<Guid>>();
public static async Task<IActionResult> UpdateRun(
[HttpTrigger(AuthorizationLevel.Admin, "post", Route = null)] HttpRequest req, ExecutionContext execContext)
{
logger.LogInformation($"FunctionUpdate Start");
using var reader = new StreamReader(req.Body);
var request = JsonConvert.DeserializeObject<IEnumerable<Request>>(reader.ReadToEnd());
var correlationIds = request?.Select(s => s.CorrelationId);
updateQueue.Enqueue(correlationIds);
return new OkObjectResult(new Response { HttpStatusCode = HttpStatusCode.Accepted });
}
[FunctionName("FunctionHandleQueue"), Timeout("00:05:00")]
public static async Task HandleQueue([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ExecutionContext execContext) // once every 1 minutes
{
logger.LogInformation($"before updateQueue condition : {updateQueue.Count}");
if (updateQueue.Count > 0)
{
logger.LogInformation($"after updateQueue condition {updateQueue.Count}");
var guids = new List<Guid>();
var count = 0;
while (count <= 1000 && updateQueue.Count > 0)
{
updateQueue.TryDequeue(out var updateRequest);
var enumerable = updateRequest.ToList();
count += enumerable.Count;
guids.AddRange(enumerable);
}
await new ProcessUpdateSales(CreateMapper(), execContext)
.Orchestrate(guids)
}
}
}
Logs are created when TimerTrigger
executes every 1 minute:
before updateQueue condition : 0
Why is updateQueue.Count
always 0? What am I doing wrong?