protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { try { var instocks = await _mongoService.GetAllInStocks(); if (instocks != null && instocks.Count > 0) { var roleId = _config.GetSection("Workers")["discordRoleId"]; await _webhookClient.SendMessageAsync($"<@&{roleId}> Remember that these items are still in stock!", false); Parallel.ForEach(instocks, async instock => { _logger.LogInformation($"Opening new thread for Product ({instock.EndpointItem.Title}) <ThreadID={Thread.CurrentThread.ManagedThreadId}>."); await _webhookClient.SendMessageAsync("", false, DiscordHelpers.BuildEmbed(instock.EndpointItem)); }); } _logger.LogInformation($"No Product are in stock currently."); } catch (Exception e) { _logger.LogError($"Snatcher Worker failed unexpectedly => {e}", e); // throw; } // 3 Days by Default await Task.Delay(int.Parse(_config.GetSection("Workers")["reminderInterval"]), stoppingToken); } }