public async Task <ActionResult <QueueStat> > GetJobQueueStat( [FromServices] RurikawaDb db, [FromServices] RedisService redis, [FromServices] JsonSerializerOptions jsonSerializerOptions ) { var red = await redis.GetDatabase(); var judgerStat = await red.StringGetAsync(QUEUE_STAT_CACHE_KEY); if (!judgerStat.IsNullOrEmpty) { return(new ContentResult() { Content = (string)judgerStat, StatusCode = 200, ContentType = "application/json" }); } // TODO: Use redis to track jobs count? var jobCount = await JudgerCoordinatorService.QueuedCriteria(db.Jobs).CountAsync(); var stat = new QueueStat { QueuedJobs = jobCount }; await red.StringSetAsync( QUEUE_STAT_CACHE_KEY, JsonSerializer.Serialize(stat, jsonSerializerOptions), expiry : TimeSpan.FromSeconds(10)); return(stat); }
private void ShowQueuesCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help") { io.Write("Show queue stats on instance"); } else if (UUID.Zero != limitedToScene) { io.Write("Not allowed on limited console"); } else { var sb = new StringBuilder("Queue List:\n----------------------------------------------"); foreach (KeyValuePair <string, IQueueStatsAccess> kvp in GetServices <IQueueStatsAccess>()) { foreach (QueueStatAccessor accessors in kvp.Value.QueueStats) { QueueStat stat = accessors.GetData(); sb.AppendFormat("\n{0}: {1}:\n- Status: {2}\n- Count: {3}\n- Processed: {4}\n", kvp.Key, accessors.Name, stat.Status, stat.Count, stat.Processed); } } io.Write(sb.ToString()); } }