diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js index 0be7d9d83..4a4c5e162 100644 --- a/server/controllers/api/videos.js +++ b/server/controllers/api/videos.js @@ -379,6 +379,9 @@ function addVideo (req, res, videoFile, finalCallback) { }, 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) diff --git a/server/lib/jobs/handlers/video-transcoder.js b/server/lib/jobs/handlers/video-transcoder.js index 8524df3aa..d2ad4f9c7 100644 --- a/server/lib/jobs/handlers/video-transcoder.js +++ b/server/lib/jobs/handlers/video-transcoder.js @@ -2,6 +2,7 @@ const db = require('../../../initializers/database') const logger = require('../../../helpers/logger') +const friends = require('../../../lib/friends') const VideoTranscoderHandler = { process, @@ -12,21 +13,29 @@ const VideoTranscoderHandler = { // --------------------------------------------------------------------------- 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) + }) } // --------------------------------------------------------------------------- diff --git a/server/lib/jobs/job-scheduler.js b/server/lib/jobs/job-scheduler.js index 589a30630..c59bf9262 100644 --- a/server/lib/jobs/job-scheduler.js +++ b/server/lib/jobs/job-scheduler.js @@ -76,31 +76,31 @@ function processJob (job, 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) }) } diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index 45969e83a..feba68d74 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js @@ -76,6 +76,7 @@ describe('Test multiple pods', function () { 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([ @@ -152,7 +153,7 @@ describe('Test multiple pods', function () { }) it('Should upload the video on pod 2 and propagate on each pod', function (done) { - this.timeout(15000) + this.timeout(30000) series([ function (next) { @@ -169,7 +170,7 @@ describe('Test multiple pods', function () { 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) {