]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/transcoding/shared/job-builders/abstract-job-builder.ts
Add runner jobs openapi
[github/Chocobozzz/PeerTube.git] / server / lib / transcoding / shared / job-builders / abstract-job-builder.ts
CommitLineData
0c9668f7
C
1
2import { JOB_PRIORITY } from '@server/initializers/constants'
3import { VideoModel } from '@server/models/video/video'
4import { MUserId, MVideoFile, MVideoFullLight } from '@server/types/models'
5
6export abstract class AbstractJobBuilder {
7
8 abstract createOptimizeOrMergeAudioJobs (options: {
9 video: MVideoFullLight
10 videoFile: MVideoFile
11 isNewVideo: boolean
12 user: MUserId
13 }): Promise<any>
14
15 abstract createTranscodingJobs (options: {
16 transcodingType: 'hls' | 'webtorrent'
17 video: MVideoFullLight
18 resolutions: number[]
19 isNewVideo: boolean
20 user: MUserId | null
21 }): Promise<any>
22
23 protected async getTranscodingJobPriority (options: {
24 user: MUserId
25 fallback: number
26 }) {
27 const { user, fallback } = options
28
29 if (!user) return fallback
30
31 const now = new Date()
32 const lastWeek = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7)
33
34 const videoUploadedByUser = await VideoModel.countVideosUploadedByUserSince(user.id, lastWeek)
35
36 return JOB_PRIORITY.TRANSCODING + videoUploadedByUser
37 }
38}