1
0
Fork 0
peertube/server/lib/schedulers/runner-job-watch-dog-scheduler.ts
Chocobozzz 0c9668f779 Implement remote runner jobs in server
Move ffmpeg functions to @shared
2023-05-09 08:57:34 +02:00

42 lines
1.5 KiB
TypeScript

import { CONFIG } from '@server/initializers/config'
import { RunnerJobModel } from '@server/models/runner/runner-job'
import { logger, loggerTagsFactory } from '../../helpers/logger'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
import { getRunnerJobHandlerClass } from '../runners'
import { AbstractScheduler } from './abstract-scheduler'
const lTags = loggerTagsFactory('runner')
export class RunnerJobWatchDogScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.RUNNER_JOB_WATCH_DOG
private constructor () {
super()
}
protected async internalExecute () {
const vodStalledJobs = await RunnerJobModel.listStalledJobs({
staleTimeMS: CONFIG.REMOTE_RUNNERS.STALLED_JOBS.VOD,
types: [ 'vod-audio-merge-transcoding', 'vod-hls-transcoding', 'vod-web-video-transcoding' ]
})
const liveStalledJobs = await RunnerJobModel.listStalledJobs({
staleTimeMS: CONFIG.REMOTE_RUNNERS.STALLED_JOBS.LIVE,
types: [ 'live-rtmp-hls-transcoding' ]
})
for (const stalled of [ ...vodStalledJobs, ...liveStalledJobs ]) {
logger.info('Abort stalled runner job %s (%s)', stalled.uuid, stalled.type, lTags(stalled.uuid, stalled.type))
const Handler = getRunnerJobHandlerClass(stalled)
await new Handler().abort({ runnerJob: stalled })
}
}
static get Instance () {
return this.instance || (this.instance = new this())
}
}