]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Server: Fix video propagation with transcoding enabled
authorChocobozzz <florian.bigard@gmail.com>
Fri, 5 May 2017 10:15:16 +0000 (12:15 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 5 May 2017 10:15:16 +0000 (12:15 +0200)
server/controllers/api/videos.js
server/lib/jobs/handlers/video-transcoder.js
server/lib/jobs/job-scheduler.js
server/tests/api/multiple-pods.js

index 0be7d9d8328f38ac84353a7c410b48607fcbfe9a..4a4c5e162c0f7b21d7586b015073db6f27812c15 100644 (file)
@@ -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)
 
index 8524df3aa05e1620c5cc97e3c9d58d22d8e7d6d0..d2ad4f9c70aeb3d0c6613962d09161cf9dd3aa5f 100644 (file)
@@ -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)
+  })
 }
 
 // ---------------------------------------------------------------------------
index 589a3063067e28111d4b7708e9359655c5497ef8..c59bf9262c399a2bcbaa8fb30178c370f4f64885 100644 (file)
@@ -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)
   })
 }
 
index 45969e83a5e2fef80d94bccff6fcdaaf1b7e9af1..feba68d743f2ffac9118311a9a4142fc223bdabd 100644 (file)
@@ -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) {