diff options
Diffstat (limited to 'server/lib/job-queue/handlers/video-file.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-file.ts | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/server/lib/job-queue/handlers/video-file.ts b/server/lib/job-queue/handlers/video-file.ts index adc0a2a15..593e43cc5 100644 --- a/server/lib/job-queue/handlers/video-file.ts +++ b/server/lib/job-queue/handlers/video-file.ts | |||
@@ -8,7 +8,8 @@ import { retryTransactionWrapper } from '../../../helpers/database-utils' | |||
8 | import { sequelizeTypescript } from '../../../initializers' | 8 | import { sequelizeTypescript } from '../../../initializers' |
9 | import * as Bluebird from 'bluebird' | 9 | import * as Bluebird from 'bluebird' |
10 | import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' | 10 | import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' |
11 | import { importVideoFile, transcodeOriginalVideofile, optimizeVideofile } from '../../video-transcoding' | 11 | import { importVideoFile, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding' |
12 | import { Notifier } from '../../notifier' | ||
12 | 13 | ||
13 | export type VideoFilePayload = { | 14 | export type VideoFilePayload = { |
14 | videoUUID: string | 15 | videoUUID: string |
@@ -67,17 +68,17 @@ async function processVideoFile (job: Bull.Job) { | |||
67 | async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { | 68 | async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { |
68 | if (video === undefined) return undefined | 69 | if (video === undefined) return undefined |
69 | 70 | ||
70 | return sequelizeTypescript.transaction(async t => { | 71 | const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => { |
71 | // Maybe the video changed in database, refresh it | 72 | // Maybe the video changed in database, refresh it |
72 | let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) | 73 | let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) |
73 | // Video does not exist anymore | 74 | // Video does not exist anymore |
74 | if (!videoDatabase) return undefined | 75 | if (!videoDatabase) return undefined |
75 | 76 | ||
76 | let isNewVideo = false | 77 | let videoPublished = false |
77 | 78 | ||
78 | // 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 |
79 | if (videoDatabase.state !== VideoState.PUBLISHED) { | 80 | if (videoDatabase.state !== VideoState.PUBLISHED) { |
80 | isNewVideo = true | 81 | videoPublished = true |
81 | 82 | ||
82 | videoDatabase.state = VideoState.PUBLISHED | 83 | videoDatabase.state = VideoState.PUBLISHED |
83 | videoDatabase.publishedAt = new Date() | 84 | videoDatabase.publishedAt = new Date() |
@@ -85,21 +86,26 @@ async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { | |||
85 | } | 86 | } |
86 | 87 | ||
87 | // 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 |
88 | await federateVideoIfNeeded(videoDatabase, isNewVideo, t) | 89 | await federateVideoIfNeeded(videoDatabase, videoPublished, t) |
89 | 90 | ||
90 | return undefined | 91 | return { videoDatabase, videoPublished } |
91 | }) | 92 | }) |
93 | |||
94 | if (videoPublished) { | ||
95 | Notifier.Instance.notifyOnNewVideo(videoDatabase) | ||
96 | Notifier.Instance.notifyOnPendingVideoPublished(videoDatabase) | ||
97 | } | ||
92 | } | 98 | } |
93 | 99 | ||
94 | async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boolean) { | 100 | async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) { |
95 | if (video === undefined) return undefined | 101 | if (videoArg === undefined) return undefined |
96 | 102 | ||
97 | // Outside the transaction (IO on disk) | 103 | // Outside the transaction (IO on disk) |
98 | const { videoFileResolution } = await video.getOriginalFileResolution() | 104 | const { videoFileResolution } = await videoArg.getOriginalFileResolution() |
99 | 105 | ||
100 | return sequelizeTypescript.transaction(async t => { | 106 | const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => { |
101 | // Maybe the video changed in database, refresh it | 107 | // Maybe the video changed in database, refresh it |
102 | const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t) | 108 | let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t) |
103 | // Video does not exist anymore | 109 | // Video does not exist anymore |
104 | if (!videoDatabase) return undefined | 110 | if (!videoDatabase) return undefined |
105 | 111 | ||
@@ -110,8 +116,10 @@ async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boole | |||
110 | { resolutions: resolutionsEnabled } | 116 | { resolutions: resolutionsEnabled } |
111 | ) | 117 | ) |
112 | 118 | ||
119 | let videoPublished = false | ||
120 | |||
113 | if (resolutionsEnabled.length !== 0) { | 121 | if (resolutionsEnabled.length !== 0) { |
114 | const tasks: Bluebird<any>[] = [] | 122 | const tasks: Bluebird<Bull.Job<any>>[] = [] |
115 | 123 | ||
116 | for (const resolution of resolutionsEnabled) { | 124 | for (const resolution of resolutionsEnabled) { |
117 | const dataInput = { | 125 | const dataInput = { |
@@ -127,15 +135,22 @@ async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boole | |||
127 | 135 | ||
128 | logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled }) | 136 | logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled }) |
129 | } else { | 137 | } else { |
138 | videoPublished = true | ||
139 | |||
130 | // No transcoding to do, it's now published | 140 | // No transcoding to do, it's now published |
131 | video.state = VideoState.PUBLISHED | 141 | videoDatabase.state = VideoState.PUBLISHED |
132 | video = await video.save({ transaction: t }) | 142 | videoDatabase = await videoDatabase.save({ transaction: t }) |
133 | 143 | ||
134 | logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid) | 144 | logger.info('No transcoding jobs created for video %s (no resolutions).', videoDatabase.uuid, { privacy: videoDatabase.privacy }) |
135 | } | 145 | } |
136 | 146 | ||
137 | return federateVideoIfNeeded(video, isNewVideo, t) | 147 | await federateVideoIfNeeded(videoDatabase, isNewVideo, t) |
148 | |||
149 | return { videoDatabase, videoPublished } | ||
138 | }) | 150 | }) |
151 | |||
152 | if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase) | ||
153 | if (videoPublished) Notifier.Instance.notifyOnPendingVideoPublished(videoDatabase) | ||
139 | } | 154 | } |
140 | 155 | ||
141 | // --------------------------------------------------------------------------- | 156 | // --------------------------------------------------------------------------- |