diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/core-utils/common/promises.ts | 15 | ||||
-rw-r--r-- | shared/models/server/job.model.ts | 6 |
2 files changed, 17 insertions, 4 deletions
diff --git a/shared/core-utils/common/promises.ts b/shared/core-utils/common/promises.ts index 7ef9d60b6..dc0db9074 100644 --- a/shared/core-utils/common/promises.ts +++ b/shared/core-utils/common/promises.ts | |||
@@ -6,7 +6,20 @@ function isCatchable (value: any) { | |||
6 | return value && typeof value.catch === 'function' | 6 | return value && typeof value.catch === 'function' |
7 | } | 7 | } |
8 | 8 | ||
9 | function timeoutPromise <T> (promise: Promise<T>, timeoutMs: number) { | ||
10 | let timer: ReturnType<typeof setTimeout> | ||
11 | |||
12 | return Promise.race([ | ||
13 | promise, | ||
14 | |||
15 | new Promise((_res, rej) => { | ||
16 | timer = setTimeout(() => rej(new Error('Timeout')), timeoutMs) | ||
17 | }) | ||
18 | ]).finally(() => clearTimeout(timer)) | ||
19 | } | ||
20 | |||
9 | export { | 21 | export { |
10 | isPromise, | 22 | isPromise, |
11 | isCatchable | 23 | isCatchable, |
24 | timeoutPromise | ||
12 | } | 25 | } |
diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts index ac10ea964..a924183f2 100644 --- a/shared/models/server/job.model.ts +++ b/shared/models/server/job.model.ts | |||
@@ -4,7 +4,7 @@ import { VideoResolution } from '../videos/file/video-resolution.enum' | |||
4 | import { VideoStudioTaskCut } from '../videos/studio' | 4 | import { VideoStudioTaskCut } from '../videos/studio' |
5 | import { SendEmailOptions } from './emailer.model' | 5 | import { SendEmailOptions } from './emailer.model' |
6 | 6 | ||
7 | export type JobState = 'active' | 'completed' | 'failed' | 'waiting' | 'delayed' | 'paused' | 7 | export type JobState = 'active' | 'completed' | 'failed' | 'waiting' | 'delayed' | 'paused' | 'waiting-children' |
8 | 8 | ||
9 | export type JobType = | 9 | export type JobType = |
10 | | 'activitypub-http-unicast' | 10 | | 'activitypub-http-unicast' |
@@ -27,8 +27,8 @@ export type JobType = | |||
27 | | 'video-studio-edition' | 27 | | 'video-studio-edition' |
28 | 28 | ||
29 | export interface Job { | 29 | export interface Job { |
30 | id: number | 30 | id: number | string |
31 | state: JobState | 31 | state: JobState | 'unknown' |
32 | type: JobType | 32 | type: JobType |
33 | data: any | 33 | data: any |
34 | priority: number | 34 | priority: number |