backend: Updated recording status when a starting timeout occurs

This commit is contained in:
Carlos Santos 2025-04-21 16:18:28 +02:00
parent b7b9f9b1c0
commit 9d42242ba0
3 changed files with 17 additions and 8 deletions

View File

@ -1,6 +1,7 @@
import { EgressInfo } from 'livekit-server-sdk';
import { MeetRecordingInfo, MeetRecordingStatus } from '@typings-ce';
import { EgressStatus } from '@livekit/protocol';
import INTERNAL_CONFIG from '../config/internal-config.js';
export class RecordingHelper {
private constructor() {
@ -29,7 +30,7 @@ export class RecordingHelper {
size,
errorCode: errorCode ? Number(errorCode) : undefined,
error: error ? String(error) : undefined,
details: details ? String(details) : undefined,
details: details ? String(details) : undefined
};
}
@ -174,6 +175,12 @@ export class RecordingHelper {
return size !== 0 ? size : undefined;
}
static buildMetadataFilePath(recordingId: string): string {
const { roomId, egressId, uid } = RecordingHelper.extractInfoFromRecordingId(recordingId);
return `${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.metadata/${roomId}/${egressId}/${uid}.json`;
}
private static toSeconds(nanoseconds: number): number {
const nanosecondsToSeconds = 1 / 1_000_000_000;
return nanoseconds * nanosecondsToSeconds;

View File

@ -184,7 +184,7 @@ export class LivekitWebhookService {
const recordingInfo: MeetRecordingInfo = RecordingHelper.toRecordingInfo(egressInfo);
const { roomId, recordingId, status } = recordingInfo;
const metadataPath = this.buildMetadataFilePath(recordingId);
const metadataPath = RecordingHelper.buildMetadataFilePath(recordingId);
this.logger.debug(`Recording '${recordingId}' status: '${status}'`);
@ -267,10 +267,4 @@ export class LivekitWebhookService {
this.logger.error(`Error saving room secrets for room ${roomId}: ${error}`);
}
}
protected buildMetadataFilePath(recordingId: string): string {
const { roomId, egressId, uid } = RecordingHelper.extractInfoFromRecordingId(recordingId);
return `${INTERNAL_CONFIG.S3_RECORDINGS_PREFIX}/.metadata/${roomId}/${egressId}/${uid}.json`;
}
}

View File

@ -498,6 +498,7 @@ export class RecordingService {
let shouldReleaseLock = false;
try {
await this.updateRecordingStatus(recordingId, MeetRecordingStatus.FAILED);
await this.stopRecording(recordingId);
// The recording was stopped successfully
// the cleanup timer will be cancelled when the egress_ended event is received.
@ -598,6 +599,13 @@ export class RecordingService {
}
}
protected async updateRecordingStatus(recordingId: string, status: MeetRecordingStatus): Promise<void> {
const metadataPath = RecordingHelper.buildMetadataFilePath(recordingId);
const recordingInfo = await this.getRecording(recordingId);
recordingInfo.status = status;
await this.s3Service.saveObject(metadataPath, recordingInfo);
}
/**
* Cleans up orphaned recording locks in the system.
*