aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/schedulers/update-videos-scheduler.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/schedulers/update-videos-scheduler.ts')
-rw-r--r--server/lib/schedulers/update-videos-scheduler.ts32
1 files changed, 15 insertions, 17 deletions
diff --git a/server/lib/schedulers/update-videos-scheduler.ts b/server/lib/schedulers/update-videos-scheduler.ts
index 3e75babcb..af69bda89 100644
--- a/server/lib/schedulers/update-videos-scheduler.ts
+++ b/server/lib/schedulers/update-videos-scheduler.ts
@@ -1,12 +1,12 @@
1import { VideoModel } from '@server/models/video/video'
2import { MVideoFullLight } from '@server/types/models'
1import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
2import { AbstractScheduler } from './abstract-scheduler' 4import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
5import { sequelizeTypescript } from '../../initializers/database'
3import { ScheduleVideoUpdateModel } from '../../models/video/schedule-video-update' 6import { ScheduleVideoUpdateModel } from '../../models/video/schedule-video-update'
4import { retryTransactionWrapper } from '../../helpers/database-utils'
5import { federateVideoIfNeeded } from '../activitypub/videos' 7import { federateVideoIfNeeded } from '../activitypub/videos'
6import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
7import { Notifier } from '../notifier' 8import { Notifier } from '../notifier'
8import { sequelizeTypescript } from '../../initializers/database' 9import { AbstractScheduler } from './abstract-scheduler'
9import { MVideoFullLight } from '@server/types/models'
10 10
11export class UpdateVideosScheduler extends AbstractScheduler { 11export class UpdateVideosScheduler extends AbstractScheduler {
12 12
@@ -19,18 +19,19 @@ export class UpdateVideosScheduler extends AbstractScheduler {
19 } 19 }
20 20
21 protected async internalExecute () { 21 protected async internalExecute () {
22 return retryTransactionWrapper(this.updateVideos.bind(this)) 22 return this.updateVideos()
23 } 23 }
24 24
25 private async updateVideos () { 25 private async updateVideos () {
26 if (!await ScheduleVideoUpdateModel.areVideosToUpdate()) return undefined 26 if (!await ScheduleVideoUpdateModel.areVideosToUpdate()) return undefined
27 27
28 const publishedVideos = await sequelizeTypescript.transaction(async t => { 28 const schedules = await ScheduleVideoUpdateModel.listVideosToUpdate()
29 const schedules = await ScheduleVideoUpdateModel.listVideosToUpdate(t) 29 const publishedVideos: MVideoFullLight[] = []
30 const publishedVideos: MVideoFullLight[] = [] 30
31 for (const schedule of schedules) {
32 await sequelizeTypescript.transaction(async t => {
33 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(schedule.videoId, t)
31 34
32 for (const schedule of schedules) {
33 const video = schedule.Video
34 logger.info('Executing scheduled video update on %s.', video.uuid) 35 logger.info('Executing scheduled video update on %s.', video.uuid)
35 36
36 if (schedule.privacy) { 37 if (schedule.privacy) {
@@ -42,16 +43,13 @@ export class UpdateVideosScheduler extends AbstractScheduler {
42 await federateVideoIfNeeded(video, isNewVideo, t) 43 await federateVideoIfNeeded(video, isNewVideo, t)
43 44
44 if (wasConfidentialVideo) { 45 if (wasConfidentialVideo) {
45 const videoToPublish: MVideoFullLight = Object.assign(video, { ScheduleVideoUpdate: schedule, UserVideoHistories: [] }) 46 publishedVideos.push(video)
46 publishedVideos.push(videoToPublish)
47 } 47 }
48 } 48 }
49 49
50 await schedule.destroy({ transaction: t }) 50 await schedule.destroy({ transaction: t })
51 } 51 })
52 52 }
53 return publishedVideos
54 })
55 53
56 for (const v of publishedVideos) { 54 for (const v of publishedVideos) {
57 Notifier.Instance.notifyOnNewVideoIfNeeded(v) 55 Notifier.Instance.notifyOnNewVideoIfNeeded(v)