async Task <object> ParseTestSuiteWrapped(Stream fileStream, FlowSnake id) => await ParseTestSuite(fileStream, id);
public async Task <Job?> GetJob(FlowSnake id) { return(await db.Jobs.Where(j => j.Id == id).AsNoTracking().SingleOrDefaultAsync()); }
public async Task <ActionResult> DumpSuiteJobs( [FromRoute] FlowSnake suiteId, [FromServices] RurikawaDb db) { var suite = await dbService.GetTestSuite(suiteId); if (suite == null) { return(NotFound()); } var columns = suite.TestGroups .SelectMany(group => group.Value.Select(value => value.Name)) .ToList(); var ptr = db.Jobs.FromSqlInterpolated($@" select distinct on (account) * from jobs where test_suite = {suiteId.Num} order by account, id desc ").AsAsyncEnumerable(); Response.StatusCode = 200; Response.ContentType = "application/csv"; const int flushInterval = 100; // write to body of response var sw = new StreamWriter(Response.Body); var csvWriter = new CsvWriter(sw); csvWriter.QuoteAllFields = true; csvWriter.WriteField("id"); csvWriter.WriteField("account"); csvWriter.WriteField("repo"); csvWriter.WriteField("revision"); csvWriter.WriteField("stage"); csvWriter.WriteField("result_kind"); foreach (var col in columns) { csvWriter.WriteField(col); } csvWriter.NextRecord(); int counter = 0; await foreach (var val in ptr) { if (counter % flushInterval == 0) { await sw.FlushAsync(); } WriteJobInfo(csvWriter, val, columns); counter++; } await sw.FlushAsync(); return(new EmptyResult()); }
public async Task <ActionResult> DumpSuiteAllJobs( [FromRoute] FlowSnake suiteId, [FromServices] RurikawaDb db) { var suite = await dbService.GetTestSuite(suiteId); if (suite == null) { return(NotFound()); } var columns = suite.TestGroups .SelectMany(group => group.Value.Select(value => value.Name)) .ToList(); Response.ContentType = "application/csv"; Response.StatusCode = 200; Response.Headers.Add("Content-Disposition", $"inline; filename=\"{suiteId}.all-jobs.csv\""); await Response.StartAsync(); // write to body of response using var sw = new StreamWriter(new StreamAsyncAdaptor(Response.Body)); await using var swGuard = sw.ConfigureAwait(false); var csvWriter = new CsvWriter(sw); const int batchSize = 100; var startId = FlowSnake.MaxValue; await WriteJobHeaders(csvWriter, columns); while (true) { var batch = db.Jobs .OrderByDescending(job => job.Id) .Where((job) => job.TestSuite == suiteId && job.Id < startId) .Take(batchSize) .Join( db.Profiles, (job) => job.Account, (profile) => profile.Username, (job, profile) => new JobDumpEntry { Job = job, StudentId = profile.StudentId }) .ToList(); if (batch.Count == 0) { break; } startId = batch.Last().Job.Id; await Task.Run(() => { foreach (var val in batch) { WriteJobInfo(csvWriter, val, columns); } }); await sw.FlushAsync(); } return(new EmptyResult()); }
public static string FormatJobStdout(FlowSnake id) => $"job:{id}:stream";
public static string FormatJobError(FlowSnake id) => $"job:{id}:error";
public async Task <List <Announcement> > GetAnnouncements([FromQuery] FlowSnake startId, int count, bool ascending) { return(await dbService.GetAnnouncements(startId, ascending, count)); }