aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-12-28 13:47:17 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-01-09 11:15:15 +0100
commite8d246d5267ea8b6b3114d4bcf4f34fe5f3a5241 (patch)
treec0986e91e6ed466af075ddac3c795894db4d0b85 /server/lib/job-queue
parentcef534ed53e4518fe0acf581bfe880788d42fc36 (diff)
downloadPeerTube-e8d246d5267ea8b6b3114d4bcf4f34fe5f3a5241.tar.gz
PeerTube-e8d246d5267ea8b6b3114d4bcf4f34fe5f3a5241.tar.zst
PeerTube-e8d246d5267ea8b6b3114d4bcf4f34fe5f3a5241.zip
Add notification settings migration
Diffstat (limited to 'server/lib/job-queue')
-rw-r--r--server/lib/job-queue/handlers/video-file.ts18
-rw-r--r--server/lib/job-queue/handlers/video-import.ts7
2 files changed, 15 insertions, 10 deletions
diff --git a/server/lib/job-queue/handlers/video-file.ts b/server/lib/job-queue/handlers/video-file.ts
index 959cc04fa..480d324dc 100644
--- a/server/lib/job-queue/handlers/video-file.ts
+++ b/server/lib/job-queue/handlers/video-file.ts
@@ -1,5 +1,5 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { VideoResolution, VideoState, Job } from '../../../../shared' 2import { VideoResolution, VideoState } from '../../../../shared'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { VideoModel } from '../../../models/video/video' 4import { VideoModel } from '../../../models/video/video'
5import { JobQueue } from '../job-queue' 5import { JobQueue } from '../job-queue'
@@ -8,7 +8,7 @@ import { retryTransactionWrapper } from '../../../helpers/database-utils'
8import { sequelizeTypescript } from '../../../initializers' 8import { sequelizeTypescript } from '../../../initializers'
9import * as Bluebird from 'bluebird' 9import * as Bluebird from 'bluebird'
10import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' 10import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils'
11import { importVideoFile, transcodeOriginalVideofile, optimizeVideofile } from '../../video-transcoding' 11import { importVideoFile, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding'
12import { Notifier } from '../../notifier' 12import { Notifier } from '../../notifier'
13 13
14export type VideoFilePayload = { 14export type VideoFilePayload = {
@@ -68,7 +68,7 @@ async function processVideoFile (job: Bull.Job) {
68async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { 68async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) {
69 if (video === undefined) return undefined 69 if (video === undefined) return undefined
70 70
71 return sequelizeTypescript.transaction(async t => { 71 const { videoDatabase, isNewVideo } = await sequelizeTypescript.transaction(async t => {
72 // Maybe the video changed in database, refresh it 72 // Maybe the video changed in database, refresh it
73 let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) 73 let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
74 // Video does not exist anymore 74 // Video does not exist anymore
@@ -87,10 +87,11 @@ async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) {
87 87
88 // If the video was not published, we consider it is a new one for other instances 88 // If the video was not published, we consider it is a new one for other instances
89 await federateVideoIfNeeded(videoDatabase, isNewVideo, t) 89 await federateVideoIfNeeded(videoDatabase, isNewVideo, t)
90 if (isNewVideo) Notifier.Instance.notifyOnNewVideo(video)
91 90
92 return undefined 91 return { videoDatabase, isNewVideo }
93 }) 92 })
93
94 if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase)
94} 95}
95 96
96async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) { 97async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) {
@@ -99,7 +100,7 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: bo
99 // Outside the transaction (IO on disk) 100 // Outside the transaction (IO on disk)
100 const { videoFileResolution } = await videoArg.getOriginalFileResolution() 101 const { videoFileResolution } = await videoArg.getOriginalFileResolution()
101 102
102 return sequelizeTypescript.transaction(async t => { 103 const videoDatabase = await sequelizeTypescript.transaction(async t => {
103 // Maybe the video changed in database, refresh it 104 // Maybe the video changed in database, refresh it
104 let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t) 105 let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t)
105 // Video does not exist anymore 106 // Video does not exist anymore
@@ -137,8 +138,11 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: bo
137 } 138 }
138 139
139 await federateVideoIfNeeded(videoDatabase, isNewVideo, t) 140 await federateVideoIfNeeded(videoDatabase, isNewVideo, t)
140 if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase) 141
142 return videoDatabase
141 }) 143 })
144
145 if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase)
142} 146}
143 147
144// --------------------------------------------------------------------------- 148// ---------------------------------------------------------------------------
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index 82edb8d5c..29cd1198c 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -180,12 +180,11 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
180 // Update video DB object 180 // Update video DB object
181 video.duration = duration 181 video.duration = duration
182 video.state = CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED 182 video.state = CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED
183 const videoUpdated = await video.save({ transaction: t }) 183 await video.save({ transaction: t })
184 184
185 // Now we can federate the video (reload from database, we need more attributes) 185 // Now we can federate the video (reload from database, we need more attributes)
186 const videoForFederation = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) 186 const videoForFederation = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
187 await federateVideoIfNeeded(videoForFederation, true, t) 187 await federateVideoIfNeeded(videoForFederation, true, t)
188 Notifier.Instance.notifyOnNewVideo(videoForFederation)
189 188
190 // Update video import object 189 // Update video import object
191 videoImport.state = VideoImportState.SUCCESS 190 videoImport.state = VideoImportState.SUCCESS
@@ -193,10 +192,12 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
193 192
194 logger.info('Video %s imported.', video.uuid) 193 logger.info('Video %s imported.', video.uuid)
195 194
196 videoImportUpdated.Video = videoUpdated 195 videoImportUpdated.Video = videoForFederation
197 return videoImportUpdated 196 return videoImportUpdated
198 }) 197 })
199 198
199 Notifier.Instance.notifyOnNewVideo(videoImportUpdated.Video)
200
200 // Create transcoding jobs? 201 // Create transcoding jobs?
201 if (videoImportUpdated.Video.state === VideoState.TO_TRANSCODE) { 202 if (videoImportUpdated.Video.state === VideoState.TO_TRANSCODE) {
202 // Put uuid because we don't have id auto incremented for now 203 // Put uuid because we don't have id auto incremented for now