public async Task <SimResponse> GetSim() { var(timestamp, sim) = await _db.GetLastSim(); return(new SimResponse { Sim = JsonDocument.Parse(sim.ToString()).RootElement, Timestamp = timestamp }); }
private async Task FutureGameDataIngestWorker() { while (true) { try { var(_, currentSim) = await _db.GetLastSim(); var season = currentSim["season"].AsInt32; var day = currentSim["day"].AsInt32; for (var futureDay = day + 1; futureDay < 99; futureDay++) { var stream = await _client.GetStreamAsync( $"https://www.blaseball.com/database/games?season={season}&day={futureDay}"); var timestamp = DateTimeOffset.UtcNow; var json = await JsonDocument.ParseAsync(stream); var updates = json.RootElement.EnumerateArray() .Select(game => new GameUpdate(timestamp, game)) .ToArray(); await _db.WriteGameUpdates(updates); Log.Information("Saved future game updates for S{Season}D{Day} at {Timestamp}", season + 1, futureDay + 1, timestamp); } } catch (Exception e) { Log.Error(e, "Error processing JS data"); } var currentTime = DateTimeOffset.Now; var currentHourSpan = TimeSpan.FromMinutes(currentTime.Minute) .Add(TimeSpan.FromSeconds(currentTime.Second)) .Add(TimeSpan.FromMilliseconds(currentTime.Millisecond)); var delayTime = TimeSpan.FromHours(1) - currentHourSpan; await Task.Delay(delayTime); } }