From f18003d0ac5c3fc6ec8de2a89102d1e1e89182df Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 27 Jul 2023 11:44:31 +0200 Subject: Improve runner management * Add ability to remove runner jobs * Add runner job state quick filter * Merge registration tokens and runners tables in the same page * Add copy button to copy registration token --- server/middlewares/validators/runners/jobs.ts | 30 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'server/middlewares/validators/runners') diff --git a/server/middlewares/validators/runners/jobs.ts b/server/middlewares/validators/runners/jobs.ts index 384b209ba..62f9340a5 100644 --- a/server/middlewares/validators/runners/jobs.ts +++ b/server/middlewares/validators/runners/jobs.ts @@ -1,8 +1,9 @@ import express from 'express' -import { body, param } from 'express-validator' -import { isUUIDValid } from '@server/helpers/custom-validators/misc' +import { body, param, query } from 'express-validator' +import { exists, isUUIDValid } from '@server/helpers/custom-validators/misc' import { isRunnerJobAbortReasonValid, + isRunnerJobArrayOfStateValid, isRunnerJobErrorMessageValid, isRunnerJobProgressValid, isRunnerJobSuccessPayloadValid, @@ -12,7 +13,9 @@ import { import { isRunnerTokenValid } from '@server/helpers/custom-validators/runners/runners' import { cleanUpReqFiles } from '@server/helpers/express-utils' import { LiveManager } from '@server/lib/live' +import { runnerJobCanBeCancelled } from '@server/lib/runners' import { RunnerJobModel } from '@server/models/runner/runner-job' +import { arrayify } from '@shared/core-utils' import { HttpStatusCode, RunnerJobLiveRTMPHLSTranscodingPrivatePayload, @@ -119,13 +122,7 @@ export const cancelRunnerJobValidator = [ (req: express.Request, res: express.Response, next: express.NextFunction) => { const runnerJob = res.locals.runnerJob - const allowedStates = new Set([ - RunnerJobState.PENDING, - RunnerJobState.PROCESSING, - RunnerJobState.WAITING_FOR_PARENT_JOB - ]) - - if (allowedStates.has(runnerJob.state) !== true) { + if (runnerJobCanBeCancelled(runnerJob) !== true) { return res.fail({ status: HttpStatusCode.BAD_REQUEST_400, message: 'Cannot cancel this job that is not in "pending", "processing" or "waiting for parent job" state', @@ -137,6 +134,21 @@ export const cancelRunnerJobValidator = [ } ] +export const listRunnerJobsValidator = [ + query('search') + .optional() + .custom(exists), + + query('stateOneOf') + .optional() + .customSanitizer(arrayify) + .custom(isRunnerJobArrayOfStateValid), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + return next() + } +] + export const runnerJobGetValidator = [ param('jobUUID').custom(isUUIDValid), -- cgit v1.2.3