},
function sendToFriends (t, video, callback) {
+ // Let transcoding job send the video to friends because the videofile extension might change
+ if (constants.CONFIG.TRANSCODING.ENABLED === true) return callback(null, t)
+
video.toAddRemoteJSON(function (err, remoteVideo) {
if (err) return callback(err)
const db = require('../../../initializers/database')
const logger = require('../../../helpers/logger')
+const friends = require('../../../lib/friends')
const VideoTranscoderHandler = {
process,
// ---------------------------------------------------------------------------
function process (data, callback) {
- db.Video.load(data.id, function (err, video) {
+ db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) {
if (err) return callback(err)
- video.transcodeVideofile(callback)
+ video.transcodeVideofile(function (err) {
+ return callback(err, video)
+ })
})
}
-function onError (err, jobId, callback) {
+function onError (err, jobId, video, callback) {
logger.error('Error when transcoding video file in job %d.', jobId, { error: err })
return callback()
}
-function onSuccess (data, jobId, callback) {
+function onSuccess (data, jobId, video, callback) {
logger.info('Job %d is a success.', jobId)
- return callback()
+
+ video.toAddRemoteJSON(function (err, remoteVideo) {
+ if (err) return callback(err)
+
+ // Now we'll add the video's meta data to our friends
+ friends.addVideoToFriends(remoteVideo, null, callback)
+ })
}
// ---------------------------------------------------------------------------
return jobHandler.process(job.handlerInputData, function (err, result) {
if (err) {
logger.error('Error in job handler %s.', job.handlerName, { error: err })
- return onJobError(jobHandler, job, callback)
+ return onJobError(jobHandler, job, result, callback)
}
- return onJobSuccess(jobHandler, job, callback)
+ return onJobSuccess(jobHandler, job, result, callback)
})
})
}
-function onJobError (jobHandler, job, callback) {
+function onJobError (jobHandler, job, jobResult, callback) {
job.state = constants.JOB_STATES.ERROR
job.save().asCallback(function (err) {
if (err) return cannotSaveJobError(err, callback)
- return jobHandler.onError(err, job.id, callback)
+ return jobHandler.onError(err, job.id, jobResult, callback)
})
}
-function onJobSuccess (jobHandler, job, callback) {
+function onJobSuccess (jobHandler, job, jobResult, callback) {
job.state = constants.JOB_STATES.SUCCESS
job.save().asCallback(function (err) {
if (err) return cannotSaveJobError(err, callback)
- return jobHandler.onSuccess(err, job.id, callback)
+ return jobHandler.onSuccess(err, job.id, jobResult, callback)
})
}
describe('Should upload the video and propagate on each pod', function () {
it('Should upload the video on pod 1 and propagate on each pod', function (done) {
+ // Pod 1 has video transcoding activated
this.timeout(15000)
series([
})
it('Should upload the video on pod 2 and propagate on each pod', function (done) {
- this.timeout(15000)
+ this.timeout(30000)
series([
function (next) {
videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next)
},
function (next) {
- setTimeout(next, 11000)
+ setTimeout(next, 22000)
}],
// All pods should have this video
function (err) {