backend: enhance stale recording evaluation logic and add comprehensive tests
This commit is contained in:
parent
3da1f0e041
commit
41e39bc3bd
@ -862,6 +862,7 @@ export class RecordingService {
|
|||||||
*/
|
*/
|
||||||
protected async evaluateAndAbortStaleRecording(egressInfo: EgressInfo): Promise<boolean> {
|
protected async evaluateAndAbortStaleRecording(egressInfo: EgressInfo): Promise<boolean> {
|
||||||
const recordingId = RecordingHelper.extractRecordingIdFromEgress(egressInfo);
|
const recordingId = RecordingHelper.extractRecordingIdFromEgress(egressInfo);
|
||||||
|
const { roomId } = RecordingHelper.extractInfoFromRecordingId(recordingId);
|
||||||
const updatedAt = RecordingHelper.extractUpdatedDate(egressInfo);
|
const updatedAt = RecordingHelper.extractUpdatedDate(egressInfo);
|
||||||
const staleAfterMs = ms(INTERNAL_CONFIG.RECORDING_STALE_AFTER);
|
const staleAfterMs = ms(INTERNAL_CONFIG.RECORDING_STALE_AFTER);
|
||||||
|
|
||||||
@ -878,17 +879,29 @@ export class RecordingService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lkRoomExists = await this.livekitService.roomExists(roomId);
|
||||||
|
const ageIsStale = updatedAt < Date.now() - staleAfterMs;
|
||||||
|
let isRecordingStale = false;
|
||||||
|
|
||||||
|
if (ageIsStale) {
|
||||||
|
if (!lkRoomExists) {
|
||||||
|
isRecordingStale = true; // There is no room and updated before stale time -> stale
|
||||||
|
} else {
|
||||||
|
const lkRoom = await this.livekitService.getRoom(roomId);
|
||||||
|
isRecordingStale = lkRoom.numPublishers === 0; // No publishers in the room and updated before stale time -> stale
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if recording has not been updated recently
|
// Check if recording has not been updated recently
|
||||||
const isStale = updatedAt < Date.now() - staleAfterMs;
|
|
||||||
|
|
||||||
this.logger.debug(`Recording ${recordingId} last updated at ${new Date(updatedAt).toISOString()}`);
|
this.logger.debug(`Recording ${recordingId} last updated at ${new Date(updatedAt).toISOString()}`);
|
||||||
|
|
||||||
if (!isStale) {
|
if (!isRecordingStale) {
|
||||||
this.logger.debug(`Recording ${recordingId} is still fresh`);
|
this.logger.debug(`Recording ${recordingId} is still fresh`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.warn(`Recording ${recordingId} is stale, aborting...`);
|
this.logger.warn(`Room ${roomId} does not exist and recording ${recordingId} is stale, aborting...`);
|
||||||
|
|
||||||
// Abort the recording
|
// Abort the recording
|
||||||
const { egressId } = RecordingHelper.extractInfoFromRecordingId(recordingId);
|
const { egressId } = RecordingHelper.extractInfoFromRecordingId(recordingId);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user