Add: backup completion notification

This commit is contained in:
Nicholas Wallace 2024-07-14 19:59:50 +00:00
parent 2aabca906e
commit b1adafedd2
4 changed files with 40 additions and 3 deletions

View file

@ -16,9 +16,10 @@ const { getFileSize } = require('../utils/fileUtils')
const Backup = require('../objects/Backup')
class BackupManager {
constructor() {
constructor(notificationManager) {
this.ItemsMetadataPath = Path.join(global.MetadataPath, 'items')
this.AuthorsMetadataPath = Path.join(global.MetadataPath, 'authors')
this.notificationManager = notificationManager
this.scheduleTask = null
@ -322,13 +323,18 @@ class BackupManager {
}
// Check remove oldest backup
if (this.backups.length > this.backupsToKeep) {
const removeOldest = this.backups.length > this.backupsToKeep
if (removeOldest) {
this.backups.sort((a, b) => a.createdAt - b.createdAt)
const oldBackup = this.backups.shift()
Logger.debug(`[BackupManager] Removing old backup ${oldBackup.id}`)
this.removeBackup(oldBackup)
}
// Notifications only for auto downloaded episodes
this.notificationManager.onBackupCompleted(newBackup, this.backups.length, removeOldest)
return true
}

View file

@ -36,6 +36,20 @@ class NotificationManager {
this.triggerNotification('onPodcastEpisodeDownloaded', eventData)
}
async onBackupCompleted(backup, totalBackupCount, removedOldest) {
if (!Database.notificationSettings.isUseable) return
Logger.debug(`[NotificationManager] onBackupCompleted: Backup completed`)
const eventData = {
completionTime: backup.createdAt,
backupPath: backup.fullPath,
backupSize: backup.fileSize,
backupCount: totalBackupCount || 'Invalid',
removedOldest: removedOldest || 'false'
}
this.triggerNotification('onBackupCompleted', eventData)
}
onTest() {
this.triggerNotification('onTest')
}