Tweaked progress output, to create task for each model

This commit is contained in:
Casper Sparre 2025-10-14 00:36:13 +02:00
parent 5553bcb4be
commit c50525bd77

View File

@ -967,16 +967,22 @@ public class Program
Console.WriteLine();
await AnsiConsole.Progress()
.Columns(new ProgressBarColumn(), new PercentageColumn(), new TaskDescriptionColumn())
.Columns(new ProgressBarColumn(), new PercentageColumn(), new TaskDescriptionColumn { Alignment = Justify.Left })
.StartAsync(RunUpdateAsync);
async Task RunUpdateAsync(ProgressContext context)
{
ProgressTask updateTask = context.AddTask($"Updating User Info for '{users.Count}' users", true, users.Count);
ProgressTask updateTask = null;
int maxUsernameLength = users.Keys.Max(s => s.Length);
foreach ((string username, long userId) in users)
{
updateTask.Description = $"Updating '{username}'";
string description = $"Updating '{username}'".PadRight(11 + maxUsernameLength);
double prevValue = updateTask?.Value ?? 0;
updateTask = context.AddTask(description, true, users.Count);
updateTask.Value = prevValue;
using (LogContext.PushProperty("Username", username))
using (LogContext.PushProperty("UserId", userId))
@ -986,20 +992,23 @@ public class Program
Log.Information("Updating User Info for for: {Username:l}");
User? user_info = await m_ApiHelper.GetUserInfo($"/users/{username}");
await dbHelper.UpdateUserInfo(username, user_info);
updateTask.Description = $"{description} - COMPLETE";
}
catch (Exception ex)
{
Log.Warning(ex, "Failed to update User Info for: {Username:l}");
AnsiConsole.Markup($"[red]Failed to update User Info for '{username}'\n[/]");
updateTask.Description = $"{description} - FAILED: {ex.Message}";
}
finally
{
updateTask.Increment(1);
updateTask.StopTask();
}
}
}
updateTask.StopTask();
}
}