aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/schedulers
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/schedulers')
-rw-r--r--server/lib/schedulers/videos-redundancy-scheduler.ts50
1 files changed, 32 insertions, 18 deletions
diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts
index 607bdf67c..c49a8c89a 100644
--- a/server/lib/schedulers/videos-redundancy-scheduler.ts
+++ b/server/lib/schedulers/videos-redundancy-scheduler.ts
@@ -70,14 +70,28 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
70 70
71 for (const redundancyModel of expired) { 71 for (const redundancyModel of expired) {
72 try { 72 try {
73 const redundancy = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy) 73 await this.extendsOrDeleteRedundancy(redundancyModel)
74 await this.extendsExpirationOf(redundancyModel, redundancy.minLifetime)
75 } catch (err) { 74 } catch (err) {
76 logger.error('Cannot extend expiration of %s video from our redundancy system.', this.buildEntryLogId(redundancyModel)) 75 logger.error('Cannot extend expiration of %s video from our redundancy system.', this.buildEntryLogId(redundancyModel))
77 } 76 }
78 } 77 }
79 } 78 }
80 79
80 private async extendsOrDeleteRedundancy (redundancyModel: VideoRedundancyModel) {
81 // Refresh the video, maybe it was deleted
82 const video = await this.loadAndRefreshVideo(redundancyModel.VideoFile.Video.url)
83
84 if (!video) {
85 logger.info('Destroying existing redundancy %s, because the associated video does not exist anymore.', redundancyModel.url)
86
87 await redundancyModel.destroy()
88 return
89 }
90
91 const redundancy = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy)
92 await this.extendsExpirationOf(redundancyModel, redundancy.minLifetime)
93 }
94
81 private async purgeRemoteExpired () { 95 private async purgeRemoteExpired () {
82 const expired = await VideoRedundancyModel.listRemoteExpired() 96 const expired = await VideoRedundancyModel.listRemoteExpired()
83 97
@@ -109,23 +123,11 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
109 const serverActor = await getServerActor() 123 const serverActor = await getServerActor()
110 124
111 for (const file of filesToDuplicate) { 125 for (const file of filesToDuplicate) {
112 // We need more attributes and check if the video still exists 126 const video = await this.loadAndRefreshVideo(file.Video.url)
113 const getVideoOptions = {
114 videoObject: file.Video.url,
115 syncParam: { likes: false, dislikes: false, shares: false, comments: false, thumbnail: false, refreshVideo: true },
116 fetchType: 'all' as 'all'
117 }
118 const { video } = await getOrCreateVideoAndAccountAndChannel(getVideoOptions)
119 127
120 const existing = await VideoRedundancyModel.loadLocalByFileId(file.id) 128 const existingRedundancy = await VideoRedundancyModel.loadLocalByFileId(file.id)
121 if (existing) { 129 if (existingRedundancy) {
122 if (video) { 130 await this.extendsOrDeleteRedundancy(existingRedundancy)
123 await this.extendsExpirationOf(existing, redundancy.minLifetime)
124 } else {
125 logger.info('Destroying existing redundancy %s, because the associated video does not exist anymore.', existing.url)
126
127 await existing.destroy()
128 }
129 131
130 continue 132 continue
131 } 133 }
@@ -203,4 +205,16 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
203 205
204 return files.reduce(fileReducer, 0) 206 return files.reduce(fileReducer, 0)
205 } 207 }
208
209 private async loadAndRefreshVideo (videoUrl: string) {
210 // We need more attributes and check if the video still exists
211 const getVideoOptions = {
212 videoObject: videoUrl,
213 syncParam: { likes: false, dislikes: false, shares: false, comments: false, thumbnail: false, refreshVideo: true },
214 fetchType: 'all' as 'all'
215 }
216 const { video } = await getOrCreateVideoAndAccountAndChannel(getVideoOptions)
217
218 return video
219 }
206} 220}