diff options
Diffstat (limited to 'server/lib/schedulers/update-videos-scheduler.ts')
-rw-r--r-- | server/lib/schedulers/update-videos-scheduler.ts | 32 |
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 @@ | |||
1 | import { VideoModel } from '@server/models/video/video' | ||
2 | import { MVideoFullLight } from '@server/types/models' | ||
1 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
2 | import { AbstractScheduler } from './abstract-scheduler' | 4 | import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' |
5 | import { sequelizeTypescript } from '../../initializers/database' | ||
3 | import { ScheduleVideoUpdateModel } from '../../models/video/schedule-video-update' | 6 | import { ScheduleVideoUpdateModel } from '../../models/video/schedule-video-update' |
4 | import { retryTransactionWrapper } from '../../helpers/database-utils' | ||
5 | import { federateVideoIfNeeded } from '../activitypub/videos' | 7 | import { federateVideoIfNeeded } from '../activitypub/videos' |
6 | import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' | ||
7 | import { Notifier } from '../notifier' | 8 | import { Notifier } from '../notifier' |
8 | import { sequelizeTypescript } from '../../initializers/database' | 9 | import { AbstractScheduler } from './abstract-scheduler' |
9 | import { MVideoFullLight } from '@server/types/models' | ||
10 | 10 | ||
11 | export class UpdateVideosScheduler extends AbstractScheduler { | 11 | export 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) |