1
0
Fork 0

Avoid update remote runner error

This commit is contained in:
Chocobozzz 2023-07-12 11:09:29 +02:00
parent d959b763f0
commit d874522774
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 57 additions and 49 deletions

View file

@ -4,12 +4,12 @@ import { proxifyHLS, proxifyWebVideoFile } from '@server/lib/object-storage'
import { VideoPathManager } from '@server/lib/video-path-manager' import { VideoPathManager } from '@server/lib/video-path-manager'
import { getStudioTaskFilePath } from '@server/lib/video-studio' import { getStudioTaskFilePath } from '@server/lib/video-studio'
import { apiRateLimiter, asyncMiddleware } from '@server/middlewares' import { apiRateLimiter, asyncMiddleware } from '@server/middlewares'
import { jobOfRunnerGetValidator } from '@server/middlewares/validators/runners' import { jobOfRunnerGetValidatorFactory } from '@server/middlewares/validators/runners'
import { import {
runnerJobGetVideoStudioTaskFileValidator, runnerJobGetVideoStudioTaskFileValidator,
runnerJobGetVideoTranscodingFileValidator runnerJobGetVideoTranscodingFileValidator
} from '@server/middlewares/validators/runners/job-files' } from '@server/middlewares/validators/runners/job-files'
import { VideoStorage } from '@shared/models' import { RunnerJobState, VideoStorage } from '@shared/models'
const lTags = loggerTagsFactory('api', 'runner') const lTags = loggerTagsFactory('api', 'runner')
@ -17,21 +17,21 @@ const runnerJobFilesRouter = express.Router()
runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality', runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/max-quality',
apiRateLimiter, apiRateLimiter,
asyncMiddleware(jobOfRunnerGetValidator), asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
asyncMiddleware(getMaxQualityVideoFile) asyncMiddleware(getMaxQualityVideoFile)
) )
runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality', runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/previews/max-quality',
apiRateLimiter, apiRateLimiter,
asyncMiddleware(jobOfRunnerGetValidator), asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
getMaxQualityVideoPreview getMaxQualityVideoPreview
) )
runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename', runnerJobFilesRouter.post('/jobs/:jobUUID/files/videos/:videoId/studio/task-files/:filename',
apiRateLimiter, apiRateLimiter,
asyncMiddleware(jobOfRunnerGetValidator), asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
asyncMiddleware(runnerJobGetVideoTranscodingFileValidator), asyncMiddleware(runnerJobGetVideoTranscodingFileValidator),
runnerJobGetVideoStudioTaskFileValidator, runnerJobGetVideoStudioTaskFileValidator,
getVideoStudioTaskFile getVideoStudioTaskFile

View file

@ -22,7 +22,7 @@ import {
cancelRunnerJobValidator, cancelRunnerJobValidator,
errorRunnerJobValidator, errorRunnerJobValidator,
getRunnerFromTokenValidator, getRunnerFromTokenValidator,
jobOfRunnerGetValidator, jobOfRunnerGetValidatorFactory,
runnerJobGetValidator, runnerJobGetValidator,
successRunnerJobValidator, successRunnerJobValidator,
updateRunnerJobValidator updateRunnerJobValidator
@ -85,7 +85,7 @@ runnerJobsRouter.post('/jobs/:jobUUID/accept',
runnerJobsRouter.post('/jobs/:jobUUID/abort', runnerJobsRouter.post('/jobs/:jobUUID/abort',
apiRateLimiter, apiRateLimiter,
asyncMiddleware(jobOfRunnerGetValidator), asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
abortRunnerJobValidator, abortRunnerJobValidator,
asyncMiddleware(abortRunnerJob) asyncMiddleware(abortRunnerJob)
) )
@ -93,13 +93,13 @@ runnerJobsRouter.post('/jobs/:jobUUID/abort',
runnerJobsRouter.post('/jobs/:jobUUID/update', runnerJobsRouter.post('/jobs/:jobUUID/update',
runnerJobUpdateVideoFiles, runnerJobUpdateVideoFiles,
apiRateLimiter, // Has to be after multer middleware to parse runner token apiRateLimiter, // Has to be after multer middleware to parse runner token
asyncMiddleware(jobOfRunnerGetValidator), asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING, RunnerJobState.COMPLETING, RunnerJobState.COMPLETED ])),
updateRunnerJobValidator, updateRunnerJobValidator,
asyncMiddleware(updateRunnerJobController) asyncMiddleware(updateRunnerJobController)
) )
runnerJobsRouter.post('/jobs/:jobUUID/error', runnerJobsRouter.post('/jobs/:jobUUID/error',
asyncMiddleware(jobOfRunnerGetValidator), asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
errorRunnerJobValidator, errorRunnerJobValidator,
asyncMiddleware(errorRunnerJob) asyncMiddleware(errorRunnerJob)
) )
@ -107,7 +107,7 @@ runnerJobsRouter.post('/jobs/:jobUUID/error',
runnerJobsRouter.post('/jobs/:jobUUID/success', runnerJobsRouter.post('/jobs/:jobUUID/success',
postRunnerJobSuccessVideoFiles, postRunnerJobSuccessVideoFiles,
apiRateLimiter, // Has to be after multer middleware to parse runner token apiRateLimiter, // Has to be after multer middleware to parse runner token
asyncMiddleware(jobOfRunnerGetValidator), asyncMiddleware(jobOfRunnerGetValidatorFactory([ RunnerJobState.PROCESSING ])),
successRunnerJobValidator, successRunnerJobValidator,
asyncMiddleware(postRunnerJobSuccess) asyncMiddleware(postRunnerJobSuccess)
) )
@ -272,6 +272,10 @@ async function updateRunnerJobController (req: express.Request, res: express.Res
const runner = runnerJob.Runner const runner = runnerJob.Runner
const body: RunnerJobUpdateBody = req.body const body: RunnerJobUpdateBody = req.body
if (runnerJob.state === RunnerJobState.COMPLETING || runnerJob.state === RunnerJobState.COMPLETED) {
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
}
const payloadBuilder = jobUpdateBuilders[runnerJob.type] const payloadBuilder = jobUpdateBuilders[runnerJob.type]
const updatePayload = payloadBuilder const updatePayload = payloadBuilder
? payloadBuilder(body.payload, req.files as UploadFiles) ? payloadBuilder(body.payload, req.files as UploadFiles)

View file

@ -159,7 +159,8 @@ export const runnerJobGetValidator = [
} }
] ]
export const jobOfRunnerGetValidator = [ export function jobOfRunnerGetValidatorFactory (allowedStates: RunnerJobState[]) {
return [
param('jobUUID').custom(isUUIDValid), param('jobUUID').custom(isUUIDValid),
body('runnerToken').custom(isRunnerTokenValid), body('runnerToken').custom(isRunnerTokenValid),
@ -184,7 +185,7 @@ export const jobOfRunnerGetValidator = [
}) })
} }
if (runnerJob.state !== RunnerJobState.PROCESSING) { if (!allowedStates.includes(runnerJob.state)) {
cleanUpReqFiles(req) cleanUpReqFiles(req)
return res.fail({ return res.fail({
@ -200,3 +201,4 @@ export const jobOfRunnerGetValidator = [
return next() return next()
} }
] ]
}

View file

@ -41,6 +41,7 @@ describe('Test managing runners', function () {
let completedJobToken: string let completedJobToken: string
let completedJobUUID: string let completedJobUUID: string
let cancelledJobToken: string
let cancelledJobUUID: string let cancelledJobUUID: string
before(async function () { before(async function () {
@ -86,6 +87,7 @@ describe('Test managing runners', function () {
{ {
const { job } = await server.runnerJobs.autoAccept({ runnerToken }) const { job } = await server.runnerJobs.autoAccept({ runnerToken })
cancelledJobToken = job.jobToken
cancelledJobUUID = job.uuid cancelledJobUUID = job.uuid
await server.runnerJobs.cancelByAdmin({ jobUUID: cancelledJobUUID }) await server.runnerJobs.cancelByAdmin({ jobUUID: cancelledJobUUID })
} }
@ -639,10 +641,10 @@ describe('Test managing runners', function () {
it('Should fail with a job not in processing state', async function () { it('Should fail with a job not in processing state', async function () {
await server.runnerJobs.update({ await server.runnerJobs.update({
jobUUID: completedJobUUID, jobUUID: cancelledJobUUID,
jobToken: completedJobToken, jobToken: cancelledJobToken,
runnerToken, runnerToken,
expectedStatus: HttpStatusCode.BAD_REQUEST_400 expectedStatus: HttpStatusCode.NOT_FOUND_404
}) })
}) })
}) })