Add:Daily cron that closes stale open playback sessions

This commit is contained in:
advplyr
2024-07-04 12:00:54 -05:00
parent 43217657d7
commit fed5ff4863
5 changed files with 56 additions and 2 deletions

View File

@@ -162,5 +162,18 @@ class ShareManager {
destroyMediaItemShare(mediaItemShareId) {
return Database.models.mediaItemShare.destroy({ where: { id: mediaItemShareId } })
}
/**
* Close open share sessions that have not been updated in the last 24 hours
*/
closeStaleOpenShareSessions() {
const updatedAtTimeCutoff = Date.now() - 1000 * 60 * 60 * 24
const staleSessions = this.openSharePlaybackSessions.filter((session) => session.updatedAt < updatedAtTimeCutoff)
for (const session of staleSessions) {
const sessionLastUpdate = new Date(session.updatedAt)
Logger.info(`[PlaybackSessionManager] Closing stale session "${session.displayTitle}" (${session.id}) last updated at ${sessionLastUpdate}`)
this.closeSharePlaybackSession(session)
}
}
}
module.exports = new ShareManager()