From 94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Jan 2018 15:05:18 +0100 Subject: Move job queue to redis We'll use it as cache in the future. /!\ You'll loose your old jobs (pending jobs too) so upgrade only when you don't have pending job anymore. --- server/controllers/api/videos/index.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index c2fdb4f95..459795141 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -12,7 +12,7 @@ import { } from '../../../initializers' import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' -import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' +import { JobQueue } from '../../../lib/job-queue' import { asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setDefaultPagination, videosAddValidator, videosGetValidator, videosRemoveValidator, videosSearchValidator, videosSortValidator, videosUpdateValidator @@ -176,18 +176,9 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi ) await Promise.all(tasks) - return sequelizeTypescript.transaction(async t => { + const videoCreated = await sequelizeTypescript.transaction(async t => { const sequelizeOptions = { transaction: t } - if (CONFIG.TRANSCODING.ENABLED === true) { - // Put uuid because we don't have id auto incremented for now - const dataInput = { - videoUUID: video.uuid - } - - await transcodingJobScheduler.createJob(t, 'videoFileOptimizer', dataInput) - } - const videoCreated = await video.save(sequelizeOptions) // Do not forget to add video channel information to the created video videoCreated.VideoChannel = res.locals.videoChannel @@ -216,6 +207,17 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi return videoCreated }) + + if (CONFIG.TRANSCODING.ENABLED === true) { + // Put uuid because we don't have id auto incremented for now + const dataInput = { + videoUUID: videoCreated.uuid + } + + await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput }) + } + + return videoCreated } async function updateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { -- cgit v1.2.3