From 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Dec 2017 17:53:50 +0100 Subject: Move models to typescript-sequelize --- .../transcoding-job-scheduler.ts | 5 +++-- .../video-file-optimizer-handler.ts | 16 ++++++++-------- .../video-file-transcoder-handler.ts | 11 +++++------ 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'server/lib/jobs/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 index c5efe8eeb..e5530a73c 100644 --- a/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts +++ b/server/lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler.ts @@ -1,14 +1,15 @@ 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' -import { VideoInstance } from '../../../models/video/video-interface' type TranscodingJobPayload = { videoUUID: string resolution?: number } -const jobHandlers: { [ handlerName: string ]: JobHandler } = { +const jobHandlers: { [ handlerName: string ]: JobHandler } = { videoFileOptimizer, videoFileTranscoder } 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 index e65ab3ee1..1786ce971 100644 --- a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts +++ b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts @@ -1,14 +1,14 @@ import * as Bluebird from 'bluebird' import { computeResolutionsToTranscode, logger } from '../../../helpers' -import { database as db } from '../../../initializers/database' -import { VideoInstance } from '../../../models' -import { sendAddVideo } from '../../activitypub/send/send-add' +import { sequelizeTypescript } from '../../../initializers' +import { VideoModel } from '../../../models/video/video' +import { shareVideoByServer } from '../../activitypub' +import { sendAddVideo } from '../../activitypub/send' import { JobScheduler } from '../job-scheduler' import { TranscodingJobPayload } from './transcoding-job-scheduler' -import { shareVideoByServer } from '../../activitypub/share' async function process (data: TranscodingJobPayload, jobId: number) { - const video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID) + 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 }) @@ -25,13 +25,13 @@ function onError (err: Error, jobId: number) { return Promise.resolve() } -async function onSuccess (jobId: number, video: VideoInstance, jobScheduler: JobScheduler) { +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 db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid) + const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid) // Video does not exist anymore if (!videoDatabase) return undefined @@ -50,7 +50,7 @@ async function onSuccess (jobId: number, video: VideoInstance, jobScheduler: Job if (resolutionsEnabled.length !== 0) { try { - await db.sequelize.transaction(async t => { + await sequelizeTypescript.transaction(async t => { const tasks: Bluebird[] = [] for (const resolution of resolutionsEnabled) { 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 index 867580200..8957b4565 100644 --- a/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts +++ b/server/lib/jobs/transcoding-job-scheduler/video-file-transcoder-handler.ts @@ -1,11 +1,10 @@ import { VideoResolution } from '../../../../shared' import { logger } from '../../../helpers' -import { database as db } from '../../../initializers/database' -import { VideoInstance } from '../../../models' -import { sendUpdateVideo } from '../../activitypub/send/send-update' +import { VideoModel } from '../../../models/video/video' +import { sendUpdateVideo } from '../../activitypub/send' async function process (data: { videoUUID: string, resolution: VideoResolution }, jobId: number) { - const video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID) + 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 }) @@ -22,13 +21,13 @@ function onError (err: Error, jobId: number) { return Promise.resolve() } -async function onSuccess (jobId: number, video: VideoInstance) { +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 db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid) + const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid) // Video does not exist anymore if (!videoDatabase) return undefined -- cgit v1.2.3