diff options
Diffstat (limited to 'server/lib/job-queue/handlers/video-file.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-file.ts | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/server/lib/job-queue/handlers/video-file.ts b/server/lib/job-queue/handlers/video-file.ts index 480d324dc..593e43cc5 100644 --- a/server/lib/job-queue/handlers/video-file.ts +++ b/server/lib/job-queue/handlers/video-file.ts | |||
@@ -68,17 +68,17 @@ async function processVideoFile (job: Bull.Job) { | |||
68 | async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { | 68 | async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { |
69 | if (video === undefined) return undefined | 69 | if (video === undefined) return undefined |
70 | 70 | ||
71 | const { videoDatabase, isNewVideo } = await sequelizeTypescript.transaction(async t => { | 71 | const { videoDatabase, videoPublished } = 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 |
75 | if (!videoDatabase) return undefined | 75 | if (!videoDatabase) return undefined |
76 | 76 | ||
77 | let isNewVideo = false | 77 | let videoPublished = false |
78 | 78 | ||
79 | // We transcoded the video file in another format, now we can publish it | 79 | // We transcoded the video file in another format, now we can publish it |
80 | if (videoDatabase.state !== VideoState.PUBLISHED) { | 80 | if (videoDatabase.state !== VideoState.PUBLISHED) { |
81 | isNewVideo = true | 81 | videoPublished = true |
82 | 82 | ||
83 | videoDatabase.state = VideoState.PUBLISHED | 83 | videoDatabase.state = VideoState.PUBLISHED |
84 | videoDatabase.publishedAt = new Date() | 84 | videoDatabase.publishedAt = new Date() |
@@ -86,12 +86,15 @@ async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { | |||
86 | } | 86 | } |
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, videoPublished, t) |
90 | 90 | ||
91 | return { videoDatabase, isNewVideo } | 91 | return { videoDatabase, videoPublished } |
92 | }) | 92 | }) |
93 | 93 | ||
94 | if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase) | 94 | if (videoPublished) { |
95 | Notifier.Instance.notifyOnNewVideo(videoDatabase) | ||
96 | Notifier.Instance.notifyOnPendingVideoPublished(videoDatabase) | ||
97 | } | ||
95 | } | 98 | } |
96 | 99 | ||
97 | async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) { | 100 | async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) { |
@@ -100,7 +103,7 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: bo | |||
100 | // Outside the transaction (IO on disk) | 103 | // Outside the transaction (IO on disk) |
101 | const { videoFileResolution } = await videoArg.getOriginalFileResolution() | 104 | const { videoFileResolution } = await videoArg.getOriginalFileResolution() |
102 | 105 | ||
103 | const videoDatabase = await sequelizeTypescript.transaction(async t => { | 106 | const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => { |
104 | // Maybe the video changed in database, refresh it | 107 | // Maybe the video changed in database, refresh it |
105 | let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t) | 108 | let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t) |
106 | // Video does not exist anymore | 109 | // Video does not exist anymore |
@@ -113,6 +116,8 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: bo | |||
113 | { resolutions: resolutionsEnabled } | 116 | { resolutions: resolutionsEnabled } |
114 | ) | 117 | ) |
115 | 118 | ||
119 | let videoPublished = false | ||
120 | |||
116 | if (resolutionsEnabled.length !== 0) { | 121 | if (resolutionsEnabled.length !== 0) { |
117 | const tasks: Bluebird<Bull.Job<any>>[] = [] | 122 | const tasks: Bluebird<Bull.Job<any>>[] = [] |
118 | 123 | ||
@@ -130,6 +135,8 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: bo | |||
130 | 135 | ||
131 | logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled }) | 136 | logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled }) |
132 | } else { | 137 | } else { |
138 | videoPublished = true | ||
139 | |||
133 | // No transcoding to do, it's now published | 140 | // No transcoding to do, it's now published |
134 | videoDatabase.state = VideoState.PUBLISHED | 141 | videoDatabase.state = VideoState.PUBLISHED |
135 | videoDatabase = await videoDatabase.save({ transaction: t }) | 142 | videoDatabase = await videoDatabase.save({ transaction: t }) |
@@ -139,10 +146,11 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: bo | |||
139 | 146 | ||
140 | await federateVideoIfNeeded(videoDatabase, isNewVideo, t) | 147 | await federateVideoIfNeeded(videoDatabase, isNewVideo, t) |
141 | 148 | ||
142 | return videoDatabase | 149 | return { videoDatabase, videoPublished } |
143 | }) | 150 | }) |
144 | 151 | ||
145 | if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase) | 152 | if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase) |
153 | if (videoPublished) Notifier.Instance.notifyOnPendingVideoPublished(videoDatabase) | ||
146 | } | 154 | } |
147 | 155 | ||
148 | // --------------------------------------------------------------------------- | 156 | // --------------------------------------------------------------------------- |