Slightly improve birthday update task handling

This commit is contained in:
Noi 2020-04-03 20:58:02 -07:00
parent 670309715b
commit c5cab92899

View file

@ -25,25 +25,25 @@ namespace BirthdayBot.BackgroundServices
var tasks = new List<Task>(); var tasks = new List<Task>();
foreach (var guild in BotInstance.DiscordClient.Guilds) foreach (var guild in BotInstance.DiscordClient.Guilds)
{ {
var t = ProcessGuildAsync(guild); tasks.Add(ProcessGuildAsync(guild));
tasks.Add(t);
} }
var alltasks = Task.WhenAll(tasks);
try try
{ {
await Task.WhenAll(tasks); await alltasks;
} }
catch (Exception ex) catch (Exception ex)
{ {
// TODO does this not actually work as might be expected? var exs = alltasks.Exception;
var exs = from task in tasks if (exs != null)
where task.Exception != null
select task.Exception;
Log($"Encountered {exs.Count()} errors during bulk guild processing.");
foreach (var iex in exs)
{ {
// TODO probably not a good idea Log($"{exs.InnerExceptions.Count} exception(s) during bulk processing!");
Log(iex.ToString()); // TODO needs major improvements. output to file?
}
else
{
Log(ex.ToString());
} }
} }