From 62326afb151a1062253ac8b08bb62ce3f01e1267 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 May 2017 12:15:16 +0200 Subject: Server: Fix video propagation with transcoding enabled --- server/lib/jobs/handlers/video-transcoder.js | 19 ++++++++++++++----- server/lib/jobs/job-scheduler.js | 12 ++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'server/lib/jobs') 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) }) } -- cgit v1.2.3