From 5e47f6ab984a7d00782e4c7030afffa1ba480add Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 May 2023 15:29:34 +0200 Subject: Support studio transcoding in peertube runner --- .../shared/job-builders/abstract-job-builder.ts | 18 ------------------ .../job-builders/transcoding-job-queue-builder.ts | 3 ++- .../job-builders/transcoding-runner-job-builder.ts | 15 ++++++++------- 3 files changed, 10 insertions(+), 26 deletions(-) (limited to 'server/lib/transcoding/shared/job-builders') diff --git a/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts b/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts index 576e786d5..80dc05bfb 100644 --- a/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts +++ b/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts @@ -1,6 +1,4 @@ -import { JOB_PRIORITY } from '@server/initializers/constants' -import { VideoModel } from '@server/models/video/video' import { MUserId, MVideoFile, MVideoFullLight } from '@server/types/models' export abstract class AbstractJobBuilder { @@ -20,20 +18,4 @@ export abstract class AbstractJobBuilder { isNewVideo: boolean user: MUserId | null }): Promise - - protected async getTranscodingJobPriority (options: { - user: MUserId - fallback: number - }) { - const { user, fallback } = options - - if (!user) return fallback - - const now = new Date() - const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7) - - const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek) - - return JOB_PRIORITY.TRANSCODING + videoUploadedByUser - } } diff --git a/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts b/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts index 5a9c93ee5..29ee2ca61 100644 --- a/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts +++ b/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts @@ -16,6 +16,7 @@ import { OptimizeTranscodingPayload, VideoTranscodingPayload } from '@shared/models' +import { getTranscodingJobPriority } from '../../transcoding-priority' import { canDoQuickTranscode } from '../../transcoding-quick-transcode' import { computeResolutionsToTranscode } from '../../transcoding-resolutions' import { AbstractJobBuilder } from './abstract-job-builder' @@ -178,7 +179,7 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder { return { type: 'video-transcoding' as 'video-transcoding', - priority: await this.getTranscodingJobPriority({ user, fallback: undefined }), + priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: undefined }), payload } } diff --git a/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts b/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts index 274dce21b..90b035402 100644 --- a/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts +++ b/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts @@ -8,6 +8,7 @@ import { VideoPathManager } from '@server/lib/video-path-manager' import { MUserId, MVideoFile, MVideoFullLight, MVideoWithFileThumbnail } from '@server/types/models' import { MRunnerJob } from '@server/types/models/runners' import { ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamFPS, hasAudioStream, isAudioFile } from '@shared/ffmpeg' +import { getTranscodingJobPriority } from '../../transcoding-priority' import { computeResolutionsToTranscode } from '../../transcoding-resolutions' import { AbstractJobBuilder } from './abstract-job-builder' @@ -49,7 +50,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { : resolution const fps = computeOutputFPS({ inputFPS, resolution: maxResolution }) - const priority = await this.getTranscodingJobPriority({ user, fallback: 0 }) + const priority = await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) const mainRunnerJob = videoFile.isAudio() ? await new VODAudioMergeTranscodingJobHandler().create({ video, resolution: maxResolution, fps, isNewVideo, priority }) @@ -63,7 +64,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { fps, isNewVideo, dependsOnRunnerJob: mainRunnerJob, - priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) + priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) }) } @@ -96,7 +97,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { const maxResolution = Math.max(...resolutions) const { fps: inputFPS } = await video.probeMaxQualityFile() const maxFPS = computeOutputFPS({ inputFPS, resolution: maxResolution }) - const priority = await this.getTranscodingJobPriority({ user, fallback: 0 }) + const priority = await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) const childrenResolutions = resolutions.filter(r => r !== maxResolution) @@ -121,7 +122,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { isNewVideo, deleteWebVideoFiles: false, dependsOnRunnerJob, - priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) + priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) }) continue } @@ -133,7 +134,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { fps, isNewVideo, dependsOnRunnerJob, - priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) + priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) }) continue } @@ -172,7 +173,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { fps, isNewVideo, dependsOnRunnerJob: mainRunnerJob, - priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) + priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) }) } @@ -184,7 +185,7 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { isNewVideo, deleteWebVideoFiles: false, dependsOnRunnerJob: mainRunnerJob, - priority: await this.getTranscodingJobPriority({ user, fallback: 0 }) + priority: await getTranscodingJobPriority({ user, type: 'vod', fallback: 0 }) }) } } -- cgit v1.2.3