Exemple #1
0
        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);
        }
Exemple #2
0
        public ActionResult SendJobResult(
            [FromBody] JobResultMsg resultMsg,
            [FromServices] JudgerCoordinatorService coordinator)
        {
            var judger = AuthHelper.ExtractUsername(HttpContext.User);

            coordinator.OnJobResultMessage(judger !, resultMsg);
            return(NoContent());
        }
        public async Task <JudgerStat> GetJudgerStat(
            [FromServices] JudgerCoordinatorService coordinatorService,
            [FromServices] RurikawaDb db)
        {
            var judgerCount = await db.Judgers.CountAsync();

            var(connectedCount, runningCount) = await coordinatorService.GetConnectedJudgerInfo();

            return(new JudgerStat
            {
                Count = judgerCount,
                Connected = connectedCount,
                Running = runningCount
            });
        }
Exemple #4
0
        public ActionResult SendJobResult(
            [FromBody] IClientResultMsg resultMsg,
            [FromServices] JudgerCoordinatorService coordinator)
        {
            var judger = AuthHelper.ExtractUsername(HttpContext.User);

            switch (resultMsg)
            {
            case JobResultMsg msg:
                coordinator.OnJobResultMessage(judger !, msg); break;

            case JobProgressMsg msg:
                coordinator.OnJobProgressMessage(judger !, msg); break;

            default:
                return(BadRequest(new ErrorResponse(
                                      ErrorCodes.INVALID_MESSAGE_TYPE,
                                      "This endpoint only accepts JobResultMsg and JobProgressMsg")));
            }
            return(NoContent());
        }
Exemple #5
0
        public async Task <ActionResult <JudgerStat> > GetJudgerStat(
            [FromServices] JudgerCoordinatorService coordinatorService,
            [FromServices] RurikawaDb db,
            [FromServices] RedisService redis,
            [FromServices] JsonSerializerOptions jsonSerializerOptions)
        {
            var red = await redis.GetDatabase();

            var judgerStat = await red.StringGetAsync(JUDGER_STAT_CACHE_KEY);

            if (!judgerStat.IsNullOrEmpty)
            {
                return(new ContentResult()
                {
                    Content = (string)judgerStat,
                    StatusCode = 200,
                    ContentType = "application/json"
                });
            }

            var judgerCount = await db.Judgers.CountAsync();

            var(connectedCount, runningCount) = await coordinatorService.GetConnectedJudgerInfo();

            var stat = new JudgerStat {
                Count     = judgerCount,
                Connected = connectedCount,
                Running   = runningCount
            };

            await red.StringSetAsync(
                JUDGER_STAT_CACHE_KEY,
                JsonSerializer.Serialize(stat, jsonSerializerOptions),
                expiry : TimeSpan.FromSeconds(10));

            return(stat);
        }
Exemple #6
0
 public JobController(ILogger <JobController> logger, DbService dbsvc, JudgerCoordinatorService coordinatorService)
 {
     this.logger             = logger;
     this.dbsvc              = dbsvc;
     this.coordinatorService = coordinatorService;
 }