aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/transcoding/shared/job-builders/abstract-job-builder.ts
blob: 576e786d5122a8fa2a0f3c9f08e62b39fce825ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 {

  abstract createOptimizeOrMergeAudioJobs (options: {
    video: MVideoFullLight
    videoFile: MVideoFile
    isNewVideo: boolean
    user: MUserId
    videoFileAlreadyLocked: boolean
  }): Promise<any>

  abstract createTranscodingJobs (options: {
    transcodingType: 'hls' | 'webtorrent'
    video: MVideoFullLight
    resolutions: number[]
    isNewVideo: boolean
    user: MUserId | null
  }): Promise<any>

  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
  }
}