diff options
-rw-r--r-- | server/controllers/api/videos.js | 3 | ||||
-rw-r--r-- | server/lib/jobs/handlers/video-transcoder.js | 19 | ||||
-rw-r--r-- | server/lib/jobs/job-scheduler.js | 12 | ||||
-rw-r--r-- | server/tests/api/multiple-pods.js | 5 |
4 files changed, 26 insertions, 13 deletions
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) { | |||
379 | }, | 379 | }, |
380 | 380 | ||
381 | function sendToFriends (t, video, callback) { | 381 | function sendToFriends (t, video, callback) { |
382 | // Let transcoding job send the video to friends because the videofile extension might change | ||
383 | if (constants.CONFIG.TRANSCODING.ENABLED === true) return callback(null, t) | ||
384 | |||
382 | video.toAddRemoteJSON(function (err, remoteVideo) { | 385 | video.toAddRemoteJSON(function (err, remoteVideo) { |
383 | if (err) return callback(err) | 386 | if (err) return callback(err) |
384 | 387 | ||
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 @@ | |||
2 | 2 | ||
3 | const db = require('../../../initializers/database') | 3 | const db = require('../../../initializers/database') |
4 | const logger = require('../../../helpers/logger') | 4 | const logger = require('../../../helpers/logger') |
5 | const friends = require('../../../lib/friends') | ||
5 | 6 | ||
6 | const VideoTranscoderHandler = { | 7 | const VideoTranscoderHandler = { |
7 | process, | 8 | process, |
@@ -12,21 +13,29 @@ const VideoTranscoderHandler = { | |||
12 | // --------------------------------------------------------------------------- | 13 | // --------------------------------------------------------------------------- |
13 | 14 | ||
14 | function process (data, callback) { | 15 | function process (data, callback) { |
15 | db.Video.load(data.id, function (err, video) { | 16 | db.Video.loadAndPopulateAuthorAndPodAndTags(data.id, function (err, video) { |
16 | if (err) return callback(err) | 17 | if (err) return callback(err) |
17 | 18 | ||
18 | video.transcodeVideofile(callback) | 19 | video.transcodeVideofile(function (err) { |
20 | return callback(err, video) | ||
21 | }) | ||
19 | }) | 22 | }) |
20 | } | 23 | } |
21 | 24 | ||
22 | function onError (err, jobId, callback) { | 25 | function onError (err, jobId, video, callback) { |
23 | logger.error('Error when transcoding video file in job %d.', jobId, { error: err }) | 26 | logger.error('Error when transcoding video file in job %d.', jobId, { error: err }) |
24 | return callback() | 27 | return callback() |
25 | } | 28 | } |
26 | 29 | ||
27 | function onSuccess (data, jobId, callback) { | 30 | function onSuccess (data, jobId, video, callback) { |
28 | logger.info('Job %d is a success.', jobId) | 31 | logger.info('Job %d is a success.', jobId) |
29 | return callback() | 32 | |
33 | video.toAddRemoteJSON(function (err, remoteVideo) { | ||
34 | if (err) return callback(err) | ||
35 | |||
36 | // Now we'll add the video's meta data to our friends | ||
37 | friends.addVideoToFriends(remoteVideo, null, callback) | ||
38 | }) | ||
30 | } | 39 | } |
31 | 40 | ||
32 | // --------------------------------------------------------------------------- | 41 | // --------------------------------------------------------------------------- |
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) { | |||
76 | return jobHandler.process(job.handlerInputData, function (err, result) { | 76 | return jobHandler.process(job.handlerInputData, function (err, result) { |
77 | if (err) { | 77 | if (err) { |
78 | logger.error('Error in job handler %s.', job.handlerName, { error: err }) | 78 | logger.error('Error in job handler %s.', job.handlerName, { error: err }) |
79 | return onJobError(jobHandler, job, callback) | 79 | return onJobError(jobHandler, job, result, callback) |
80 | } | 80 | } |
81 | 81 | ||
82 | return onJobSuccess(jobHandler, job, callback) | 82 | return onJobSuccess(jobHandler, job, result, callback) |
83 | }) | 83 | }) |
84 | }) | 84 | }) |
85 | } | 85 | } |
86 | 86 | ||
87 | function onJobError (jobHandler, job, callback) { | 87 | function onJobError (jobHandler, job, jobResult, callback) { |
88 | job.state = constants.JOB_STATES.ERROR | 88 | job.state = constants.JOB_STATES.ERROR |
89 | 89 | ||
90 | job.save().asCallback(function (err) { | 90 | job.save().asCallback(function (err) { |
91 | if (err) return cannotSaveJobError(err, callback) | 91 | if (err) return cannotSaveJobError(err, callback) |
92 | 92 | ||
93 | return jobHandler.onError(err, job.id, callback) | 93 | return jobHandler.onError(err, job.id, jobResult, callback) |
94 | }) | 94 | }) |
95 | } | 95 | } |
96 | 96 | ||
97 | function onJobSuccess (jobHandler, job, callback) { | 97 | function onJobSuccess (jobHandler, job, jobResult, callback) { |
98 | job.state = constants.JOB_STATES.SUCCESS | 98 | job.state = constants.JOB_STATES.SUCCESS |
99 | 99 | ||
100 | job.save().asCallback(function (err) { | 100 | job.save().asCallback(function (err) { |
101 | if (err) return cannotSaveJobError(err, callback) | 101 | if (err) return cannotSaveJobError(err, callback) |
102 | 102 | ||
103 | return jobHandler.onSuccess(err, job.id, callback) | 103 | return jobHandler.onSuccess(err, job.id, jobResult, callback) |
104 | }) | 104 | }) |
105 | } | 105 | } |
106 | 106 | ||
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 () { | |||
76 | 76 | ||
77 | describe('Should upload the video and propagate on each pod', function () { | 77 | describe('Should upload the video and propagate on each pod', function () { |
78 | it('Should upload the video on pod 1 and propagate on each pod', function (done) { | 78 | it('Should upload the video on pod 1 and propagate on each pod', function (done) { |
79 | // Pod 1 has video transcoding activated | ||
79 | this.timeout(15000) | 80 | this.timeout(15000) |
80 | 81 | ||
81 | series([ | 82 | series([ |
@@ -152,7 +153,7 @@ describe('Test multiple pods', function () { | |||
152 | }) | 153 | }) |
153 | 154 | ||
154 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { | 155 | it('Should upload the video on pod 2 and propagate on each pod', function (done) { |
155 | this.timeout(15000) | 156 | this.timeout(30000) |
156 | 157 | ||
157 | series([ | 158 | series([ |
158 | function (next) { | 159 | function (next) { |
@@ -169,7 +170,7 @@ describe('Test multiple pods', function () { | |||
169 | videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next) | 170 | videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next) |
170 | }, | 171 | }, |
171 | function (next) { | 172 | function (next) { |
172 | setTimeout(next, 11000) | 173 | setTimeout(next, 22000) |
173 | }], | 174 | }], |
174 | // All pods should have this video | 175 | // All pods should have this video |
175 | function (err) { | 176 | function (err) { |