diff options
author | Chocobozzz <me@florianbigard.com> | 2023-06-19 13:45:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-06-19 13:45:26 +0200 |
commit | a34c612f38af9c5f2c9f53931ed9df35ac834e90 (patch) | |
tree | 3d8f2b8a0d5c93dbe14a668cfe76cb974ce9ae74 /shared | |
parent | 7d758898dc907b8643bab6ae2e70c3ca2a021fac (diff) | |
download | PeerTube-a34c612f38af9c5f2c9f53931ed9df35ac834e90.tar.gz PeerTube-a34c612f38af9c5f2c9f53931ed9df35ac834e90.tar.zst PeerTube-a34c612f38af9c5f2c9f53931ed9df35ac834e90.zip |
More robust runner update handler
Diffstat (limited to 'shared')
-rw-r--r-- | shared/ffmpeg/ffmpeg-command-wrapper.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/shared/ffmpeg/ffmpeg-command-wrapper.ts b/shared/ffmpeg/ffmpeg-command-wrapper.ts index 7a8c19d4b..efb75c198 100644 --- a/shared/ffmpeg/ffmpeg-command-wrapper.ts +++ b/shared/ffmpeg/ffmpeg-command-wrapper.ts | |||
@@ -21,6 +21,8 @@ export interface FFmpegCommandWrapperOptions { | |||
21 | lTags?: { tags: string[] } | 21 | lTags?: { tags: string[] } |
22 | 22 | ||
23 | updateJobProgress?: (progress?: number) => void | 23 | updateJobProgress?: (progress?: number) => void |
24 | onEnd?: () => void | ||
25 | onError?: (err: Error) => void | ||
24 | } | 26 | } |
25 | 27 | ||
26 | export class FFmpegCommandWrapper { | 28 | export class FFmpegCommandWrapper { |
@@ -37,6 +39,8 @@ export class FFmpegCommandWrapper { | |||
37 | private readonly lTags: { tags: string[] } | 39 | private readonly lTags: { tags: string[] } |
38 | 40 | ||
39 | private readonly updateJobProgress: (progress?: number) => void | 41 | private readonly updateJobProgress: (progress?: number) => void |
42 | private readonly onEnd?: () => void | ||
43 | private readonly onError?: (err: Error) => void | ||
40 | 44 | ||
41 | private command: FfmpegCommand | 45 | private command: FfmpegCommand |
42 | 46 | ||
@@ -48,7 +52,11 @@ export class FFmpegCommandWrapper { | |||
48 | this.threads = options.threads | 52 | this.threads = options.threads |
49 | this.logger = options.logger | 53 | this.logger = options.logger |
50 | this.lTags = options.lTags || { tags: [] } | 54 | this.lTags = options.lTags || { tags: [] } |
55 | |||
51 | this.updateJobProgress = options.updateJobProgress | 56 | this.updateJobProgress = options.updateJobProgress |
57 | |||
58 | this.onEnd = options.onEnd | ||
59 | this.onError = options.onError | ||
52 | } | 60 | } |
53 | 61 | ||
54 | getAvailableEncoders () { | 62 | getAvailableEncoders () { |
@@ -101,12 +109,16 @@ export class FFmpegCommandWrapper { | |||
101 | this.command.on('error', (err, stdout, stderr) => { | 109 | this.command.on('error', (err, stdout, stderr) => { |
102 | if (silent !== true) this.logger.error('Error in ffmpeg.', { stdout, stderr, shellCommand, ...this.lTags }) | 110 | if (silent !== true) this.logger.error('Error in ffmpeg.', { stdout, stderr, shellCommand, ...this.lTags }) |
103 | 111 | ||
112 | if (this.onError) this.onError(err) | ||
113 | |||
104 | rej(err) | 114 | rej(err) |
105 | }) | 115 | }) |
106 | 116 | ||
107 | this.command.on('end', (stdout, stderr) => { | 117 | this.command.on('end', (stdout, stderr) => { |
108 | this.logger.debug('FFmpeg command ended.', { stdout, stderr, shellCommand, ...this.lTags }) | 118 | this.logger.debug('FFmpeg command ended.', { stdout, stderr, shellCommand, ...this.lTags }) |
109 | 119 | ||
120 | if (this.onEnd) this.onEnd() | ||
121 | |||
110 | res() | 122 | res() |
111 | }) | 123 | }) |
112 | 124 | ||