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/lib/jobs/transcoding-job-scheduler/index.ts | 1 - .../transcoding-job-scheduler.ts | 23 ------ .../video-file-optimizer-handler.ts | 90 ---------------------- .../video-file-transcoder-handler.ts | 48 ------------ 4 files changed, 162 deletions(-) delete mode 100644 server/lib/jobs/transcoding-job-scheduler/index.ts delete mode 100644 server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts delete mode 100644 server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts delete mode 100644 server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts (limited to 'server/lib/jobs/transcoding-job-scheduler') diff --git a/server/lib/jobs/transcoding-job-scheduler/index.ts b/server/lib/jobs/transcoding-job-scheduler/index.ts deleted file mode 100644 index 73152a1be..000000000 --- a/server/lib/jobs/transcoding-job-scheduler/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './transcoding-job-scheduler' diff --git a/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts b/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts deleted file mode 100644 index e5530a73c..000000000 --- a/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { JobCategory } from '../../../../shared' -import { VideoModel } from '../../../models/video/video' -import { JobHandler, JobScheduler } from '../job-scheduler' - -import * as videoFileOptimizer from './video-file-optimizer-handler' -import * as videoFileTranscoder from './video-file-transcoder-handler' - -type TranscodingJobPayload = { - videoUUID: string - resolution?: number -} -const jobHandlers: { [ handlerName: string ]: JobHandler } = { - videoFileOptimizer, - videoFileTranscoder -} -const jobCategory: JobCategory = 'transcoding' - -const transcodingJobScheduler = new JobScheduler(jobCategory, jobHandlers) - -export { - TranscodingJobPayload, - transcodingJobScheduler -} diff --git a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts deleted file mode 100644 index f224a31b4..000000000 --- a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts +++ /dev/null @@ -1,90 +0,0 @@ -import * as Bluebird from 'bluebird' -import { VideoPrivacy } from '../../../../shared/models/videos' -import { logger } from '../../../helpers/logger' -import { computeResolutionsToTranscode } from '../../../helpers/utils' -import { sequelizeTypescript } from '../../../initializers' -import { JobModel } from '../../../models/job/job' -import { VideoModel } from '../../../models/video/video' -import { shareVideoByServerAndChannel } from '../../activitypub' -import { sendCreateVideo } from '../../activitypub/send' -import { JobScheduler } from '../job-scheduler' -import { TranscodingJobPayload } from './transcoding-job-scheduler' - -async function process (data: TranscodingJobPayload, jobId: number) { - const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID) - // No video, maybe deleted? - if (!video) { - logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid }) - return undefined - } - - await video.optimizeOriginalVideofile() - - return video -} - -function onError (err: Error, jobId: number) { - logger.error('Error when optimized video file in job %d.', jobId, err) - return Promise.resolve() -} - -async function onSuccess (jobId: number, video: VideoModel, jobScheduler: JobScheduler) { - if (video === undefined) return undefined - - logger.info('Job %d is a success.', jobId) - - // Maybe the video changed in database, refresh it - const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid) - // Video does not exist anymore - if (!videoDatabase) return undefined - - if (video.privacy !== VideoPrivacy.PRIVATE) { - // Now we'll add the video's meta data to our followers - await sendCreateVideo(video, undefined) - await shareVideoByServerAndChannel(video, undefined) - } - - const originalFileHeight = await videoDatabase.getOriginalFileHeight() - - // Create transcoding jobs if there are enabled resolutions - const resolutionsEnabled = computeResolutionsToTranscode(originalFileHeight) - logger.info( - 'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, originalFileHeight, - { resolutions: resolutionsEnabled } - ) - - if (resolutionsEnabled.length !== 0) { - try { - await sequelizeTypescript.transaction(async t => { - const tasks: Bluebird[] = [] - - for (const resolution of resolutionsEnabled) { - const dataInput = { - videoUUID: videoDatabase.uuid, - resolution - } - - const p = jobScheduler.createJob(t, 'videoFileTranscoder', dataInput) - tasks.push(p) - } - - await Promise.all(tasks) - }) - - logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled }) - } catch (err) { - logger.warn('Cannot transcode the video.', err) - } - } else { - logger.info('No transcoding jobs created for video %s (no resolutions enabled).') - return undefined - } -} - -// --------------------------------------------------------------------------- - -export { - process, - onError, - onSuccess -} diff --git a/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts deleted file mode 100644 index 883d3eba8..000000000 --- a/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { VideoResolution } from '../../../../shared' -import { VideoPrivacy } from '../../../../shared/models/videos' -import { logger } from '../../../helpers/logger' -import { VideoModel } from '../../../models/video/video' -import { sendUpdateVideo } from '../../activitypub/send' - -async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) { - const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID) - // No video, maybe deleted? - if (!video) { - logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid }) - return undefined - } - - await video.transcodeOriginalVideofile(data.resolution) - - return video -} - -function onError (err: Error, jobId: number) { - logger.error('Error when transcoding video file in job %d.', jobId, err) - return Promise.resolve() -} - -async function onSuccess (jobId: number, video: VideoModel) { - if (video === undefined) return undefined - - logger.info('Job %d is a success.', jobId) - - // Maybe the video changed in database, refresh it - const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid) - // Video does not exist anymore - if (!videoDatabase) return undefined - - if (video.privacy !== VideoPrivacy.PRIVATE) { - await sendUpdateVideo(video, undefined) - } - - return undefined -} - -// --------------------------------------------------------------------------- - -export { - process, - onError, - onSuccess -} -- cgit v1.2.3