aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/models/runners
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-04-21 14:55:10 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commit0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch)
tree226d3dd1565b0bb56588897af3b8530e6216e96b /shared/models/runners
parent6bcb854cdea8688a32240bc5719c7d139806e00b (diff)
downloadPeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.gz
PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.zst
PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.zip
Implement remote runner jobs in server
Move ffmpeg functions to @shared
Diffstat (limited to 'shared/models/runners')
-rw-r--r--shared/models/runners/abort-runner-job-body.model.ts6
-rw-r--r--shared/models/runners/accept-runner-job-body.model.ts3
-rw-r--r--shared/models/runners/accept-runner-job-result.model.ts6
-rw-r--r--shared/models/runners/error-runner-job-body.model.ts6
-rw-r--r--shared/models/runners/index.ts21
-rw-r--r--shared/models/runners/list-runner-jobs-query.model.ts6
-rw-r--r--shared/models/runners/list-runner-registration-tokens.model.ts5
-rw-r--r--shared/models/runners/list-runners-query.model.ts5
-rw-r--r--shared/models/runners/register-runner-body.model.ts6
-rw-r--r--shared/models/runners/register-runner-result.model.ts4
-rw-r--r--shared/models/runners/request-runner-job-body.model.ts3
-rw-r--r--shared/models/runners/request-runner-job-result.model.ts10
-rw-r--r--shared/models/runners/runner-job-payload.model.ts68
-rw-r--r--shared/models/runners/runner-job-private-payload.model.ts34
-rw-r--r--shared/models/runners/runner-job-state.model.ts10
-rw-r--r--shared/models/runners/runner-job-success-body.model.ts41
-rw-r--r--shared/models/runners/runner-job-type.type.ts5
-rw-r--r--shared/models/runners/runner-job-update-body.model.ts28
-rw-r--r--shared/models/runners/runner-job.model.ts45
-rw-r--r--shared/models/runners/runner-registration-token.ts10
-rw-r--r--shared/models/runners/runner.model.ts12
-rw-r--r--shared/models/runners/unregister-runner-body.model.ts3
22 files changed, 337 insertions, 0 deletions
diff --git a/shared/models/runners/abort-runner-job-body.model.ts b/shared/models/runners/abort-runner-job-body.model.ts
new file mode 100644
index 000000000..0b9c46c91
--- /dev/null
+++ b/shared/models/runners/abort-runner-job-body.model.ts
@@ -0,0 +1,6 @@
1export interface AbortRunnerJobBody {
2 runnerToken: string
3 jobToken: string
4
5 reason: string
6}
diff --git a/shared/models/runners/accept-runner-job-body.model.ts b/shared/models/runners/accept-runner-job-body.model.ts
new file mode 100644
index 000000000..cb266c4e6
--- /dev/null
+++ b/shared/models/runners/accept-runner-job-body.model.ts
@@ -0,0 +1,3 @@
1export interface AcceptRunnerJobBody {
2 runnerToken: string
3}
diff --git a/shared/models/runners/accept-runner-job-result.model.ts b/shared/models/runners/accept-runner-job-result.model.ts
new file mode 100644
index 000000000..f2094b945
--- /dev/null
+++ b/shared/models/runners/accept-runner-job-result.model.ts
@@ -0,0 +1,6 @@
1import { RunnerJobPayload } from './runner-job-payload.model'
2import { RunnerJob } from './runner-job.model'
3
4export interface AcceptRunnerJobResult <T extends RunnerJobPayload = RunnerJobPayload> {
5 job: RunnerJob<T> & { jobToken: string }
6}
diff --git a/shared/models/runners/error-runner-job-body.model.ts b/shared/models/runners/error-runner-job-body.model.ts
new file mode 100644
index 000000000..ac8568409
--- /dev/null
+++ b/shared/models/runners/error-runner-job-body.model.ts
@@ -0,0 +1,6 @@
1export interface ErrorRunnerJobBody {
2 runnerToken: string
3 jobToken: string
4
5 message: string
6}
diff --git a/shared/models/runners/index.ts b/shared/models/runners/index.ts
new file mode 100644
index 000000000..a52b82d2e
--- /dev/null
+++ b/shared/models/runners/index.ts
@@ -0,0 +1,21 @@
1export * from './abort-runner-job-body.model'
2export * from './accept-runner-job-body.model'
3export * from './accept-runner-job-result.model'
4export * from './error-runner-job-body.model'
5export * from './list-runner-jobs-query.model'
6export * from './list-runner-registration-tokens.model'
7export * from './list-runners-query.model'
8export * from './register-runner-body.model'
9export * from './register-runner-result.model'
10export * from './request-runner-job-body.model'
11export * from './request-runner-job-result.model'
12export * from './runner-job-payload.model'
13export * from './runner-job-private-payload.model'
14export * from './runner-job-state.model'
15export * from './runner-job-success-body.model'
16export * from './runner-job-type.type'
17export * from './runner-job-update-body.model'
18export * from './runner-job.model'
19export * from './runner-registration-token'
20export * from './runner.model'
21export * from './unregister-runner-body.model'
diff --git a/shared/models/runners/list-runner-jobs-query.model.ts b/shared/models/runners/list-runner-jobs-query.model.ts
new file mode 100644
index 000000000..a5b62c55d
--- /dev/null
+++ b/shared/models/runners/list-runner-jobs-query.model.ts
@@ -0,0 +1,6 @@
1export interface ListRunnerJobsQuery {
2 start?: number
3 count?: number
4 sort?: string
5 search?: string
6}
diff --git a/shared/models/runners/list-runner-registration-tokens.model.ts b/shared/models/runners/list-runner-registration-tokens.model.ts
new file mode 100644
index 000000000..872e059cf
--- /dev/null
+++ b/shared/models/runners/list-runner-registration-tokens.model.ts
@@ -0,0 +1,5 @@
1export interface ListRunnerRegistrationTokensQuery {
2 start?: number
3 count?: number
4 sort?: string
5}
diff --git a/shared/models/runners/list-runners-query.model.ts b/shared/models/runners/list-runners-query.model.ts
new file mode 100644
index 000000000..d4362e4c5
--- /dev/null
+++ b/shared/models/runners/list-runners-query.model.ts
@@ -0,0 +1,5 @@
1export interface ListRunnersQuery {
2 start?: number
3 count?: number
4 sort?: string
5}
diff --git a/shared/models/runners/register-runner-body.model.ts b/shared/models/runners/register-runner-body.model.ts
new file mode 100644
index 000000000..969bb35e1
--- /dev/null
+++ b/shared/models/runners/register-runner-body.model.ts
@@ -0,0 +1,6 @@
1export interface RegisterRunnerBody {
2 registrationToken: string
3
4 name: string
5 description?: string
6}
diff --git a/shared/models/runners/register-runner-result.model.ts b/shared/models/runners/register-runner-result.model.ts
new file mode 100644
index 000000000..e31776c6a
--- /dev/null
+++ b/shared/models/runners/register-runner-result.model.ts
@@ -0,0 +1,4 @@
1export interface RegisterRunnerResult {
2 id: number
3 runnerToken: string
4}
diff --git a/shared/models/runners/request-runner-job-body.model.ts b/shared/models/runners/request-runner-job-body.model.ts
new file mode 100644
index 000000000..0970d9007
--- /dev/null
+++ b/shared/models/runners/request-runner-job-body.model.ts
@@ -0,0 +1,3 @@
1export interface RequestRunnerJobBody {
2 runnerToken: string
3}
diff --git a/shared/models/runners/request-runner-job-result.model.ts b/shared/models/runners/request-runner-job-result.model.ts
new file mode 100644
index 000000000..98601c42c
--- /dev/null
+++ b/shared/models/runners/request-runner-job-result.model.ts
@@ -0,0 +1,10 @@
1import { RunnerJobPayload } from './runner-job-payload.model'
2import { RunnerJobType } from './runner-job-type.type'
3
4export interface RequestRunnerJobResult <P extends RunnerJobPayload = RunnerJobPayload> {
5 availableJobs: {
6 uuid: string
7 type: RunnerJobType
8 payload: P
9 }[]
10}
diff --git a/shared/models/runners/runner-job-payload.model.ts b/shared/models/runners/runner-job-payload.model.ts
new file mode 100644
index 000000000..8f0c17135
--- /dev/null
+++ b/shared/models/runners/runner-job-payload.model.ts
@@ -0,0 +1,68 @@
1export type RunnerJobVODPayload =
2 RunnerJobVODWebVideoTranscodingPayload |
3 RunnerJobVODHLSTranscodingPayload |
4 RunnerJobVODAudioMergeTranscodingPayload
5
6export type RunnerJobPayload =
7 RunnerJobVODPayload |
8 RunnerJobLiveRTMPHLSTranscodingPayload
9
10// ---------------------------------------------------------------------------
11
12export interface RunnerJobVODWebVideoTranscodingPayload {
13 input: {
14 videoFileUrl: string
15 }
16
17 output: {
18 resolution: number
19 fps: number
20 }
21}
22
23export interface RunnerJobVODHLSTranscodingPayload {
24 input: {
25 videoFileUrl: string
26 }
27
28 output: {
29 resolution: number
30 fps: number
31 }
32}
33
34export interface RunnerJobVODAudioMergeTranscodingPayload {
35 input: {
36 audioFileUrl: string
37 previewFileUrl: string
38 }
39
40 output: {
41 resolution: number
42 fps: number
43 }
44}
45
46// ---------------------------------------------------------------------------
47
48export function isAudioMergeTranscodingPayload (payload: RunnerJobPayload): payload is RunnerJobVODAudioMergeTranscodingPayload {
49 return !!(payload as RunnerJobVODAudioMergeTranscodingPayload).input.audioFileUrl
50}
51
52// ---------------------------------------------------------------------------
53
54export interface RunnerJobLiveRTMPHLSTranscodingPayload {
55 input: {
56 rtmpUrl: string
57 }
58
59 output: {
60 toTranscode: {
61 resolution: number
62 fps: number
63 }[]
64
65 segmentDuration: number
66 segmentListSize: number
67 }
68}
diff --git a/shared/models/runners/runner-job-private-payload.model.ts b/shared/models/runners/runner-job-private-payload.model.ts
new file mode 100644
index 000000000..c1d8d1045
--- /dev/null
+++ b/shared/models/runners/runner-job-private-payload.model.ts
@@ -0,0 +1,34 @@
1export type RunnerJobVODPrivatePayload =
2 RunnerJobVODWebVideoTranscodingPrivatePayload |
3 RunnerJobVODAudioMergeTranscodingPrivatePayload |
4 RunnerJobVODHLSTranscodingPrivatePayload
5
6export type RunnerJobPrivatePayload =
7 RunnerJobVODPrivatePayload |
8 RunnerJobLiveRTMPHLSTranscodingPrivatePayload
9
10// ---------------------------------------------------------------------------
11
12export interface RunnerJobVODWebVideoTranscodingPrivatePayload {
13 videoUUID: string
14 isNewVideo: boolean
15}
16
17export interface RunnerJobVODAudioMergeTranscodingPrivatePayload {
18 videoUUID: string
19 isNewVideo: boolean
20}
21
22export interface RunnerJobVODHLSTranscodingPrivatePayload {
23 videoUUID: string
24 isNewVideo: boolean
25 deleteWebVideoFiles: boolean
26}
27
28// ---------------------------------------------------------------------------
29
30export interface RunnerJobLiveRTMPHLSTranscodingPrivatePayload {
31 videoUUID: string
32 masterPlaylistName: string
33 outputDirectory: string
34}
diff --git a/shared/models/runners/runner-job-state.model.ts b/shared/models/runners/runner-job-state.model.ts
new file mode 100644
index 000000000..738db38b7
--- /dev/null
+++ b/shared/models/runners/runner-job-state.model.ts
@@ -0,0 +1,10 @@
1export enum RunnerJobState {
2 PENDING = 1,
3 PROCESSING = 2,
4 COMPLETED = 3,
5 ERRORED = 4,
6 WAITING_FOR_PARENT_JOB = 5,
7 CANCELLED = 6,
8 PARENT_ERRORED = 7,
9 PARENT_CANCELLED = 8
10}
diff --git a/shared/models/runners/runner-job-success-body.model.ts b/shared/models/runners/runner-job-success-body.model.ts
new file mode 100644
index 000000000..223b7552d
--- /dev/null
+++ b/shared/models/runners/runner-job-success-body.model.ts
@@ -0,0 +1,41 @@
1export interface RunnerJobSuccessBody {
2 runnerToken: string
3 jobToken: string
4
5 payload: RunnerJobSuccessPayload
6}
7
8// ---------------------------------------------------------------------------
9
10export type RunnerJobSuccessPayload =
11 VODWebVideoTranscodingSuccess |
12 VODHLSTranscodingSuccess |
13 VODAudioMergeTranscodingSuccess |
14 LiveRTMPHLSTranscodingSuccess
15
16export interface VODWebVideoTranscodingSuccess {
17 videoFile: Blob | string
18}
19
20export interface VODHLSTranscodingSuccess {
21 videoFile: Blob | string
22 resolutionPlaylistFile: Blob | string
23}
24
25export interface VODAudioMergeTranscodingSuccess {
26 videoFile: Blob | string
27}
28
29export interface LiveRTMPHLSTranscodingSuccess {
30
31}
32
33export function isWebVideoOrAudioMergeTranscodingPayloadSuccess (
34 payload: RunnerJobSuccessPayload
35): payload is VODHLSTranscodingSuccess | VODAudioMergeTranscodingSuccess {
36 return !!(payload as VODHLSTranscodingSuccess | VODAudioMergeTranscodingSuccess)?.videoFile
37}
38
39export function isHLSTranscodingPayloadSuccess (payload: RunnerJobSuccessPayload): payload is VODHLSTranscodingSuccess {
40 return !!(payload as VODHLSTranscodingSuccess)?.resolutionPlaylistFile
41}
diff --git a/shared/models/runners/runner-job-type.type.ts b/shared/models/runners/runner-job-type.type.ts
new file mode 100644
index 000000000..36d3b9b25
--- /dev/null
+++ b/shared/models/runners/runner-job-type.type.ts
@@ -0,0 +1,5 @@
1export type RunnerJobType =
2 'vod-web-video-transcoding' |
3 'vod-hls-transcoding' |
4 'vod-audio-merge-transcoding' |
5 'live-rtmp-hls-transcoding'
diff --git a/shared/models/runners/runner-job-update-body.model.ts b/shared/models/runners/runner-job-update-body.model.ts
new file mode 100644
index 000000000..ed94bbe63
--- /dev/null
+++ b/shared/models/runners/runner-job-update-body.model.ts
@@ -0,0 +1,28 @@
1export interface RunnerJobUpdateBody {
2 runnerToken: string
3 jobToken: string
4
5 progress?: number
6 payload?: RunnerJobUpdatePayload
7}
8
9// ---------------------------------------------------------------------------
10
11export type RunnerJobUpdatePayload = LiveRTMPHLSTranscodingUpdatePayload
12
13export interface LiveRTMPHLSTranscodingUpdatePayload {
14 type: 'add-chunk' | 'remove-chunk'
15
16 masterPlaylistFile?: Blob | string
17
18 resolutionPlaylistFilename?: string
19 resolutionPlaylistFile?: Blob | string
20
21 videoChunkFilename: string
22 videoChunkFile?: Blob | string
23}
24
25export function isLiveRTMPHLSTranscodingUpdatePayload (value: RunnerJobUpdatePayload): value is LiveRTMPHLSTranscodingUpdatePayload {
26 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
27 return !!(value as LiveRTMPHLSTranscodingUpdatePayload)?.videoChunkFilename
28}
diff --git a/shared/models/runners/runner-job.model.ts b/shared/models/runners/runner-job.model.ts
new file mode 100644
index 000000000..080093563
--- /dev/null
+++ b/shared/models/runners/runner-job.model.ts
@@ -0,0 +1,45 @@
1import { VideoConstant } from '../videos'
2import { RunnerJobPayload } from './runner-job-payload.model'
3import { RunnerJobPrivatePayload } from './runner-job-private-payload.model'
4import { RunnerJobState } from './runner-job-state.model'
5import { RunnerJobType } from './runner-job-type.type'
6
7export interface RunnerJob <T extends RunnerJobPayload = RunnerJobPayload> {
8 uuid: string
9
10 type: RunnerJobType
11
12 state: VideoConstant<RunnerJobState>
13
14 payload: T
15
16 failures: number
17 error: string | null
18
19 progress: number
20 priority: number
21
22 startedAt: Date | string
23 createdAt: Date | string
24 updatedAt: Date | string
25 finishedAt: Date | string
26
27 parent?: {
28 type: RunnerJobType
29 state: VideoConstant<RunnerJobState>
30 uuid: string
31 }
32
33 // If associated to a runner
34 runner?: {
35 id: number
36 name: string
37
38 description: string
39 }
40}
41
42// eslint-disable-next-line max-len
43export interface RunnerJobAdmin <T extends RunnerJobPayload = RunnerJobPayload, U extends RunnerJobPrivatePayload = RunnerJobPrivatePayload> extends RunnerJob<T> {
44 privatePayload: U
45}
diff --git a/shared/models/runners/runner-registration-token.ts b/shared/models/runners/runner-registration-token.ts
new file mode 100644
index 000000000..0a157aa51
--- /dev/null
+++ b/shared/models/runners/runner-registration-token.ts
@@ -0,0 +1,10 @@
1export interface RunnerRegistrationToken {
2 id: number
3
4 registrationToken: string
5
6 createdAt: Date
7 updatedAt: Date
8
9 registeredRunnersCount: number
10}
diff --git a/shared/models/runners/runner.model.ts b/shared/models/runners/runner.model.ts
new file mode 100644
index 000000000..3284f2992
--- /dev/null
+++ b/shared/models/runners/runner.model.ts
@@ -0,0 +1,12 @@
1export interface Runner {
2 id: number
3
4 name: string
5 description: string
6
7 ip: string
8 lastContact: Date | string
9
10 createdAt: Date | string
11 updatedAt: Date | string
12}
diff --git a/shared/models/runners/unregister-runner-body.model.ts b/shared/models/runners/unregister-runner-body.model.ts
new file mode 100644
index 000000000..d3465c5d6
--- /dev/null
+++ b/shared/models/runners/unregister-runner-body.model.ts
@@ -0,0 +1,3 @@
1export interface UnregisterRunnerBody {
2 runnerToken: string
3}