aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-11 14:33:16 +0200
committerChocobozzz <me@florianbigard.com>2021-06-11 14:33:34 +0200
commitfd6a74a83594bfb59e28bf9cae71a39884ebcc2f (patch)
treee1ba2f28ac76c0a3af54448c401063c9ad2702e4 /server/lib
parent20a206c3d12ad285c31411cd506cede791958322 (diff)
downloadPeerTube-fd6a74a83594bfb59e28bf9cae71a39884ebcc2f.tar.gz
PeerTube-fd6a74a83594bfb59e28bf9cae71a39884ebcc2f.tar.zst
PeerTube-fd6a74a83594bfb59e28bf9cae71a39884ebcc2f.zip
Refactor schedule update
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/schedulers/update-videos-scheduler.ts21
1 files changed, 10 insertions, 11 deletions
diff --git a/server/lib/schedulers/update-videos-scheduler.ts b/server/lib/schedulers/update-videos-scheduler.ts
index 3e75babcb..e61d4c2ac 100644
--- a/server/lib/schedulers/update-videos-scheduler.ts
+++ b/server/lib/schedulers/update-videos-scheduler.ts
@@ -7,6 +7,7 @@ import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
7import { Notifier } from '../notifier' 7import { Notifier } from '../notifier'
8import { sequelizeTypescript } from '../../initializers/database' 8import { sequelizeTypescript } from '../../initializers/database'
9import { MVideoFullLight } from '@server/types/models' 9import { MVideoFullLight } from '@server/types/models'
10import { VideoModel } from '@server/models/video/video'
10 11
11export class UpdateVideosScheduler extends AbstractScheduler { 12export class UpdateVideosScheduler extends AbstractScheduler {
12 13
@@ -25,12 +26,13 @@ export class UpdateVideosScheduler extends AbstractScheduler {
25 private async updateVideos () { 26 private async updateVideos () {
26 if (!await ScheduleVideoUpdateModel.areVideosToUpdate()) return undefined 27 if (!await ScheduleVideoUpdateModel.areVideosToUpdate()) return undefined
27 28
28 const publishedVideos = await sequelizeTypescript.transaction(async t => { 29 const schedules = await ScheduleVideoUpdateModel.listVideosToUpdate()
29 const schedules = await ScheduleVideoUpdateModel.listVideosToUpdate(t) 30 const publishedVideos: MVideoFullLight[] = []
30 const publishedVideos: MVideoFullLight[] = [] 31
32 for (const schedule of schedules) {
33 await sequelizeTypescript.transaction(async t => {
34 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(schedule.videoId, t)
31 35
32 for (const schedule of schedules) {
33 const video = schedule.Video
34 logger.info('Executing scheduled video update on %s.', video.uuid) 36 logger.info('Executing scheduled video update on %s.', video.uuid)
35 37
36 if (schedule.privacy) { 38 if (schedule.privacy) {
@@ -42,16 +44,13 @@ export class UpdateVideosScheduler extends AbstractScheduler {
42 await federateVideoIfNeeded(video, isNewVideo, t) 44 await federateVideoIfNeeded(video, isNewVideo, t)
43 45
44 if (wasConfidentialVideo) { 46 if (wasConfidentialVideo) {
45 const videoToPublish: MVideoFullLight = Object.assign(video, { ScheduleVideoUpdate: schedule, UserVideoHistories: [] }) 47 publishedVideos.push(video)
46 publishedVideos.push(videoToPublish)
47 } 48 }
48 } 49 }
49 50
50 await schedule.destroy({ transaction: t }) 51 await schedule.destroy({ transaction: t })
51 } 52 })
52 53 }
53 return publishedVideos
54 })
55 54
56 for (const v of publishedVideos) { 55 for (const v of publishedVideos) {
57 Notifier.Instance.notifyOnNewVideoIfNeeded(v) 56 Notifier.Instance.notifyOnNewVideoIfNeeded(v)