Check video exists before extending its expiration
This commit is contained in:
parent
5bc8745ef9
commit
be691a57c5
|
@ -70,14 +70,28 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
|
||||||
|
|
||||||
for (const redundancyModel of expired) {
|
for (const redundancyModel of expired) {
|
||||||
try {
|
try {
|
||||||
const redundancy = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy)
|
await this.extendsOrDeleteRedundancy(redundancyModel)
|
||||||
await this.extendsExpirationOf(redundancyModel, redundancy.minLifetime)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Cannot extend expiration of %s video from our redundancy system.', this.buildEntryLogId(redundancyModel))
|
logger.error('Cannot extend expiration of %s video from our redundancy system.', this.buildEntryLogId(redundancyModel))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async extendsOrDeleteRedundancy (redundancyModel: VideoRedundancyModel) {
|
||||||
|
// Refresh the video, maybe it was deleted
|
||||||
|
const video = await this.loadAndRefreshVideo(redundancyModel.VideoFile.Video.url)
|
||||||
|
|
||||||
|
if (!video) {
|
||||||
|
logger.info('Destroying existing redundancy %s, because the associated video does not exist anymore.', redundancyModel.url)
|
||||||
|
|
||||||
|
await redundancyModel.destroy()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const redundancy = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy)
|
||||||
|
await this.extendsExpirationOf(redundancyModel, redundancy.minLifetime)
|
||||||
|
}
|
||||||
|
|
||||||
private async purgeRemoteExpired () {
|
private async purgeRemoteExpired () {
|
||||||
const expired = await VideoRedundancyModel.listRemoteExpired()
|
const expired = await VideoRedundancyModel.listRemoteExpired()
|
||||||
|
|
||||||
|
@ -109,23 +123,11 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
|
||||||
const serverActor = await getServerActor()
|
const serverActor = await getServerActor()
|
||||||
|
|
||||||
for (const file of filesToDuplicate) {
|
for (const file of filesToDuplicate) {
|
||||||
// We need more attributes and check if the video still exists
|
const video = await this.loadAndRefreshVideo(file.Video.url)
|
||||||
const getVideoOptions = {
|
|
||||||
videoObject: file.Video.url,
|
|
||||||
syncParam: { likes: false, dislikes: false, shares: false, comments: false, thumbnail: false, refreshVideo: true },
|
|
||||||
fetchType: 'all' as 'all'
|
|
||||||
}
|
|
||||||
const { video } = await getOrCreateVideoAndAccountAndChannel(getVideoOptions)
|
|
||||||
|
|
||||||
const existing = await VideoRedundancyModel.loadLocalByFileId(file.id)
|
const existingRedundancy = await VideoRedundancyModel.loadLocalByFileId(file.id)
|
||||||
if (existing) {
|
if (existingRedundancy) {
|
||||||
if (video) {
|
await this.extendsOrDeleteRedundancy(existingRedundancy)
|
||||||
await this.extendsExpirationOf(existing, redundancy.minLifetime)
|
|
||||||
} else {
|
|
||||||
logger.info('Destroying existing redundancy %s, because the associated video does not exist anymore.', existing.url)
|
|
||||||
|
|
||||||
await existing.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -203,4 +205,16 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
|
||||||
|
|
||||||
return files.reduce(fileReducer, 0)
|
return files.reduce(fileReducer, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async loadAndRefreshVideo (videoUrl: string) {
|
||||||
|
// We need more attributes and check if the video still exists
|
||||||
|
const getVideoOptions = {
|
||||||
|
videoObject: videoUrl,
|
||||||
|
syncParam: { likes: false, dislikes: false, shares: false, comments: false, thumbnail: false, refreshVideo: true },
|
||||||
|
fetchType: 'all' as 'all'
|
||||||
|
}
|
||||||
|
const { video } = await getOrCreateVideoAndAccountAndChannel(getVideoOptions)
|
||||||
|
|
||||||
|
return video
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue