@@ -70,14 +70,28 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
70
70
71
71
for ( const redundancyModel of expired ) {
72
72
try {
73
- const redundancy = CONFIG . REDUNDANCY . VIDEOS . STRATEGIES . find ( s => s . strategy === redundancyModel . strategy )
74
- await this . extendsExpirationOf ( redundancyModel , redundancy . minLifetime )
73
+ await this . extendsOrDeleteRedundancy ( redundancyModel )
75
74
} catch ( err ) {
76
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
95
private async purgeRemoteExpired ( ) {
82
96
const expired = await VideoRedundancyModel . listRemoteExpired ( )
83
97
@@ -109,23 +123,11 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
109
123
const serverActor = await getServerActor ( )
110
124
111
125
for ( const file of filesToDuplicate ) {
112
- // We need more attributes and check if the video still exists
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 )
126
+ const video = await this . loadAndRefreshVideo ( file . Video . url )
119
127
120
- const existing = await VideoRedundancyModel . loadLocalByFileId ( file . id )
121
- if ( existing ) {
122
- if ( video ) {
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
- }
128
+ const existingRedundancy = await VideoRedundancyModel . loadLocalByFileId ( file . id )
129
+ if ( existingRedundancy ) {
130
+ await this . extendsOrDeleteRedundancy ( existingRedundancy )
129
131
130
132
continue
131
133
}
@@ -203,4 +205,16 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
203
205
204
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
}
0 commit comments