From a34c612f38af9c5f2c9f53931ed9df35ac834e90 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 19 Jun 2023 13:45:26 +0200 Subject: More robust runner update handler --- shared/ffmpeg/ffmpeg-command-wrapper.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'shared/ffmpeg/ffmpeg-command-wrapper.ts') 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 { lTags?: { tags: string[] } updateJobProgress?: (progress?: number) => void + onEnd?: () => void + onError?: (err: Error) => void } export class FFmpegCommandWrapper { @@ -37,6 +39,8 @@ export class FFmpegCommandWrapper { private readonly lTags: { tags: string[] } private readonly updateJobProgress: (progress?: number) => void + private readonly onEnd?: () => void + private readonly onError?: (err: Error) => void private command: FfmpegCommand @@ -48,7 +52,11 @@ export class FFmpegCommandWrapper { this.threads = options.threads this.logger = options.logger this.lTags = options.lTags || { tags: [] } + this.updateJobProgress = options.updateJobProgress + + this.onEnd = options.onEnd + this.onError = options.onError } getAvailableEncoders () { @@ -101,12 +109,16 @@ export class FFmpegCommandWrapper { this.command.on('error', (err, stdout, stderr) => { if (silent !== true) this.logger.error('Error in ffmpeg.', { stdout, stderr, shellCommand, ...this.lTags }) + if (this.onError) this.onError(err) + rej(err) }) this.command.on('end', (stdout, stderr) => { this.logger.debug('FFmpeg command ended.', { stdout, stderr, shellCommand, ...this.lTags }) + if (this.onEnd) this.onEnd() + res() }) -- cgit v1.2.3