diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 14:55:10 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | 0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch) | |
tree | 226d3dd1565b0bb56588897af3b8530e6216e96b /shared/models/runners | |
parent | 6bcb854cdea8688a32240bc5719c7d139806e00b (diff) | |
download | PeerTube-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')
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 @@ | |||
1 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | import { RunnerJobPayload } from './runner-job-payload.model' | ||
2 | import { RunnerJob } from './runner-job.model' | ||
3 | |||
4 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | export * from './abort-runner-job-body.model' | ||
2 | export * from './accept-runner-job-body.model' | ||
3 | export * from './accept-runner-job-result.model' | ||
4 | export * from './error-runner-job-body.model' | ||
5 | export * from './list-runner-jobs-query.model' | ||
6 | export * from './list-runner-registration-tokens.model' | ||
7 | export * from './list-runners-query.model' | ||
8 | export * from './register-runner-body.model' | ||
9 | export * from './register-runner-result.model' | ||
10 | export * from './request-runner-job-body.model' | ||
11 | export * from './request-runner-job-result.model' | ||
12 | export * from './runner-job-payload.model' | ||
13 | export * from './runner-job-private-payload.model' | ||
14 | export * from './runner-job-state.model' | ||
15 | export * from './runner-job-success-body.model' | ||
16 | export * from './runner-job-type.type' | ||
17 | export * from './runner-job-update-body.model' | ||
18 | export * from './runner-job.model' | ||
19 | export * from './runner-registration-token' | ||
20 | export * from './runner.model' | ||
21 | export * 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 @@ | |||
1 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | import { RunnerJobPayload } from './runner-job-payload.model' | ||
2 | import { RunnerJobType } from './runner-job-type.type' | ||
3 | |||
4 | export 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 @@ | |||
1 | export type RunnerJobVODPayload = | ||
2 | RunnerJobVODWebVideoTranscodingPayload | | ||
3 | RunnerJobVODHLSTranscodingPayload | | ||
4 | RunnerJobVODAudioMergeTranscodingPayload | ||
5 | |||
6 | export type RunnerJobPayload = | ||
7 | RunnerJobVODPayload | | ||
8 | RunnerJobLiveRTMPHLSTranscodingPayload | ||
9 | |||
10 | // --------------------------------------------------------------------------- | ||
11 | |||
12 | export interface RunnerJobVODWebVideoTranscodingPayload { | ||
13 | input: { | ||
14 | videoFileUrl: string | ||
15 | } | ||
16 | |||
17 | output: { | ||
18 | resolution: number | ||
19 | fps: number | ||
20 | } | ||
21 | } | ||
22 | |||
23 | export interface RunnerJobVODHLSTranscodingPayload { | ||
24 | input: { | ||
25 | videoFileUrl: string | ||
26 | } | ||
27 | |||
28 | output: { | ||
29 | resolution: number | ||
30 | fps: number | ||
31 | } | ||
32 | } | ||
33 | |||
34 | export 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 | |||
48 | export function isAudioMergeTranscodingPayload (payload: RunnerJobPayload): payload is RunnerJobVODAudioMergeTranscodingPayload { | ||
49 | return !!(payload as RunnerJobVODAudioMergeTranscodingPayload).input.audioFileUrl | ||
50 | } | ||
51 | |||
52 | // --------------------------------------------------------------------------- | ||
53 | |||
54 | export 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 @@ | |||
1 | export type RunnerJobVODPrivatePayload = | ||
2 | RunnerJobVODWebVideoTranscodingPrivatePayload | | ||
3 | RunnerJobVODAudioMergeTranscodingPrivatePayload | | ||
4 | RunnerJobVODHLSTranscodingPrivatePayload | ||
5 | |||
6 | export type RunnerJobPrivatePayload = | ||
7 | RunnerJobVODPrivatePayload | | ||
8 | RunnerJobLiveRTMPHLSTranscodingPrivatePayload | ||
9 | |||
10 | // --------------------------------------------------------------------------- | ||
11 | |||
12 | export interface RunnerJobVODWebVideoTranscodingPrivatePayload { | ||
13 | videoUUID: string | ||
14 | isNewVideo: boolean | ||
15 | } | ||
16 | |||
17 | export interface RunnerJobVODAudioMergeTranscodingPrivatePayload { | ||
18 | videoUUID: string | ||
19 | isNewVideo: boolean | ||
20 | } | ||
21 | |||
22 | export interface RunnerJobVODHLSTranscodingPrivatePayload { | ||
23 | videoUUID: string | ||
24 | isNewVideo: boolean | ||
25 | deleteWebVideoFiles: boolean | ||
26 | } | ||
27 | |||
28 | // --------------------------------------------------------------------------- | ||
29 | |||
30 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | export interface RunnerJobSuccessBody { | ||
2 | runnerToken: string | ||
3 | jobToken: string | ||
4 | |||
5 | payload: RunnerJobSuccessPayload | ||
6 | } | ||
7 | |||
8 | // --------------------------------------------------------------------------- | ||
9 | |||
10 | export type RunnerJobSuccessPayload = | ||
11 | VODWebVideoTranscodingSuccess | | ||
12 | VODHLSTranscodingSuccess | | ||
13 | VODAudioMergeTranscodingSuccess | | ||
14 | LiveRTMPHLSTranscodingSuccess | ||
15 | |||
16 | export interface VODWebVideoTranscodingSuccess { | ||
17 | videoFile: Blob | string | ||
18 | } | ||
19 | |||
20 | export interface VODHLSTranscodingSuccess { | ||
21 | videoFile: Blob | string | ||
22 | resolutionPlaylistFile: Blob | string | ||
23 | } | ||
24 | |||
25 | export interface VODAudioMergeTranscodingSuccess { | ||
26 | videoFile: Blob | string | ||
27 | } | ||
28 | |||
29 | export interface LiveRTMPHLSTranscodingSuccess { | ||
30 | |||
31 | } | ||
32 | |||
33 | export function isWebVideoOrAudioMergeTranscodingPayloadSuccess ( | ||
34 | payload: RunnerJobSuccessPayload | ||
35 | ): payload is VODHLSTranscodingSuccess | VODAudioMergeTranscodingSuccess { | ||
36 | return !!(payload as VODHLSTranscodingSuccess | VODAudioMergeTranscodingSuccess)?.videoFile | ||
37 | } | ||
38 | |||
39 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | export interface RunnerJobUpdateBody { | ||
2 | runnerToken: string | ||
3 | jobToken: string | ||
4 | |||
5 | progress?: number | ||
6 | payload?: RunnerJobUpdatePayload | ||
7 | } | ||
8 | |||
9 | // --------------------------------------------------------------------------- | ||
10 | |||
11 | export type RunnerJobUpdatePayload = LiveRTMPHLSTranscodingUpdatePayload | ||
12 | |||
13 | export 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 | |||
25 | export 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 @@ | |||
1 | import { VideoConstant } from '../videos' | ||
2 | import { RunnerJobPayload } from './runner-job-payload.model' | ||
3 | import { RunnerJobPrivatePayload } from './runner-job-private-payload.model' | ||
4 | import { RunnerJobState } from './runner-job-state.model' | ||
5 | import { RunnerJobType } from './runner-job-type.type' | ||
6 | |||
7 | export 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 | ||
43 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | export interface UnregisterRunnerBody { | ||
2 | runnerToken: string | ||
3 | } | ||