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 5a7e9ed74e
commit 333e91d01c

View File

@ -967,16 +967,22 @@ public class Program
Console.WriteLine(); Console.WriteLine();
await AnsiConsole.Progress() await AnsiConsole.Progress()
.Columns(new ProgressBarColumn(), new PercentageColumn(), new TaskDescriptionColumn()) .Columns(new ProgressBarColumn(), new PercentageColumn(), new TaskDescriptionColumn { Alignment = Justify.Left })
.StartAsync(RunUpdateAsync); .StartAsync(RunUpdateAsync);
async Task RunUpdateAsync(ProgressContext context) 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) 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("Username", username))
using (LogContext.PushProperty("UserId", userId)) using (LogContext.PushProperty("UserId", userId))
@ -986,22 +992,25 @@ public class Program
Log.Information("Updating User Info for for: {Username:l}"); Log.Information("Updating User Info for for: {Username:l}");
User? user_info = await m_ApiHelper.GetUserInfo(username, $"/users/{username}"); User? user_info = await m_ApiHelper.GetUserInfo(username, $"/users/{username}");
await dbHelper.UpdateUserInfo(username, user_info); await dbHelper.UpdateUserInfo(username, user_info);
updateTask.Description = $"{description} - COMPLETE";
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Warning(ex, "Failed to update User Info for: {Username:l}"); Log.Warning(ex, "Failed to update User Info for: {Username:l}");
AnsiConsole.Markup($"[red]Failed to update User Info for '{username}'\n[/]"); AnsiConsole.Markup($"[red]Failed to update User Info for '{username}'\n[/]");
updateTask.Description = $"{description} - FAILED: {ex.Message}";
} }
finally finally
{ {
updateTask.Increment(1); updateTask.Increment(1);
}
}
}
updateTask.StopTask(); updateTask.StopTask();
} }
} }
}
}
}
private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Entities.Config Config) private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Entities.Config Config)
{ {