/* eslint-disable no-underscore-dangle */ /** * @module long-worker.ts * @description Implements a class for media view log-running task workers */ // npm import * as Sentry from '@sentry/node'; // @ownzones import { Task } from '@ownzones/rrtq'; // app import { ConfigType, log } from '../../config'; import { AudioDemux, IAudioDemuxTask } from './audio-demux'; import { SegmentType } from '../playlist-builder'; import { BaseWorker } from './base-worker'; /** * Class for media view long-running task workers */ export class LongWorker extends BaseWorker { //---------------------------------------------------- // #region - class methods //---------------------------------------------------- /** * Create a LongWorker instance and subscribes it to Rrtq. * @param configuration - the worker configuration * @param namespace - the associated Rrtq namespace */ public constructor(configuration: ConfigType, namespace: string) { super(configuration, namespace); } /** * Worker function, handles the supplied task * @param queueTask - the task to be handled, should have a payload of type IAudioDemuxTask */ /* eslint-disable class-methods-use-this */ protected async workerFunc(queueTask: Task) : Promise { const task = queueTask.payload as IAudioDemuxTask; if (task.type !== SegmentType.ExtractAudioChannels) { throw new Error(`Wrong task type ${task.type} provided`); } try { const t0 = new Date(); log.debug(`Execute new task - taskId ${queueTask.id} `, { ...task, content: null }); const taskBuilder = new AudioDemux(task); await taskBuilder.run(); const took = (Date.now() - t0.getTime()) / 1000; log.debug(`Segment ${queueTask.id} took ${took}s`, { took, id: queueTask.id, ...task }); } catch (err) { const error = err as Error; if ((error.message.includes('HTTP error 403') || error.message.includes('HTTP error 400'))) { Sentry.captureException(error); } throw error; } return task; } //---------------------------------------------------- // #endregion - class methods //---------------------------------------------------- }