Skip to content

Commit

Permalink
[server] silly diagnostic tool that downloads all songs
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowsink committed Oct 11, 2023
1 parent 08d3417 commit 57e8f5e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions UwuRadio.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@

var app = builder.Build();

// UwuRadio.Server --cache-all
// debug tool that downloads all songs in ingest.
#if DEBUG
if (args.Contains("--cache-all"))
{
Helpers.Log("debug cache-all", "Starting full ingest cache...");
var dataSrv = app.Services.GetService<DataService>()!;
var dlSrv = app.Services.GetService<DownloadService>()!;

foreach (var song in dataSrv.Songs) dlSrv.EnsureDownloaded(song);

foreach (var (song, idx) in dataSrv.Songs.Select((s, idx) => (s, idx)))
{
while (!dlSrv.IsDownloaded(song) && !dlSrv.IsBlacklisted(song))
// lol this makes the entire program wrapped in an async state machine in debug builds :)
await Task.Delay(100);

Helpers.Log("debug cache-all", $"downloaded: {idx} of {dataSrv.Songs.Length}");
}

Helpers.Log("debug cache-all", "successfully downloaded all songs");

return;
}
#endif

// https://stackoverflow.com/a/66240442/8388655
app.UseCors(cors => cors.AllowAnyHeader().AllowAnyMethod().SetIsOriginAllowed(_ => true).AllowCredentials());

Expand All @@ -30,6 +56,7 @@
});

// start the services way before they're technically needed so that it starts downloading instantly
// to clarify: without this, the server would sit until someone tried to listen, then cold-start.
app.Services.GetService<CoordinatorService>();

Helpers.Log(null, "Kickstarted services successfully, starting web server now");
Expand Down

0 comments on commit 57e8f5e

Please sign in to comment.