import * as Bluebird from 'bluebird'
+import { computeResolutionsToTranscode, logger } from '../../../helpers'
import { database as db } from '../../../initializers/database'
-import { logger, computeResolutionsToTranscode } from '../../../helpers'
import { VideoInstance } from '../../../models'
-import { addVideoToFriends } from '../../friends'
+
import { JobScheduler } from '../job-scheduler'
+import { TranscodingJobPayload } from './transcoding-job-scheduler'
+import { shareVideoByServer } from '../../../helpers/activitypub'
+import { sendAddVideo } from '../../activitypub/send/send-add'
-async function process (data: { videoUUID: string }, jobId: number) {
- const video = await db.Video.loadByUUIDAndPopulateAccountAndPodAndTags(data.videoUUID)
+async function process (data: TranscodingJobPayload, jobId: number) {
+ const video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
// No video, maybe deleted?
if (!video) {
logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
return Promise.resolve()
}
-async function onSuccess (jobId: number, video: VideoInstance) {
+async function onSuccess (jobId: number, video: VideoInstance, jobScheduler: JobScheduler<TranscodingJobPayload, VideoInstance>) {
if (video === undefined) return undefined
logger.info('Job %d is a success.', jobId)
// Maybe the video changed in database, refresh it
- const videoDatabase = await db.Video.loadByUUIDAndPopulateAccountAndPodAndTags(video.uuid)
+ const videoDatabase = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
// Video does not exist anymore
if (!videoDatabase) return undefined
- const remoteVideo = await videoDatabase.toAddRemoteJSON()
-
- // Now we'll add the video's meta data to our friends
- await addVideoToFriends(remoteVideo, null)
+ // Now we'll add the video's meta data to our followers
+ await sendAddVideo(video, undefined)
+ await shareVideoByServer(video, undefined)
const originalFileHeight = await videoDatabase.getOriginalFileHeight()
- // Create transcoding jobs if there are enabled resolutions
+ // Create transcoding jobs if there are enabled resolutions
const resolutionsEnabled = computeResolutionsToTranscode(originalFileHeight)
logger.info(
'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, originalFileHeight,
resolution
}
- const p = JobScheduler.Instance.createJob(t, 'videoFileTranscoder', dataInput)
+ const p = jobScheduler.createJob(t, 'videoFileTranscoder', dataInput)
tasks.push(p)
}