Add ability to manually run transcoding job
This commit is contained in:
parent
b4f8277cb6
commit
0c948c1659
6 changed files with 154 additions and 10 deletions
|
@ -36,6 +36,7 @@
|
||||||
"dev:client": "scripty",
|
"dev:client": "scripty",
|
||||||
"start": "node dist/server",
|
"start": "node dist/server",
|
||||||
"update-host": "node ./dist/scripts/update-host.js",
|
"update-host": "node ./dist/scripts/update-host.js",
|
||||||
|
"create-transcoding-job": "node ./dist/scripts/create-transcoding-job.js",
|
||||||
"test": "scripty",
|
"test": "scripty",
|
||||||
"help": "scripty",
|
"help": "scripty",
|
||||||
"generate-api-doc": "scripty",
|
"generate-api-doc": "scripty",
|
||||||
|
|
39
scripts/create-transcoding-job.ts
Executable file
39
scripts/create-transcoding-job.ts
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
import * as program from 'commander'
|
||||||
|
import { createReadStream } from 'fs'
|
||||||
|
import { join } from 'path'
|
||||||
|
import { createInterface } from 'readline'
|
||||||
|
import { VideoModel } from '../server/models/video/video'
|
||||||
|
import { initDatabaseModels } from '../server/initializers'
|
||||||
|
import { JobQueue } from '../server/lib/job-queue'
|
||||||
|
|
||||||
|
program
|
||||||
|
.option('-v, --video [videoUUID]', 'Video UUID')
|
||||||
|
.parse(process.argv)
|
||||||
|
|
||||||
|
if (program['video'] === undefined) {
|
||||||
|
console.error('All parameters are mandatory.')
|
||||||
|
process.exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
||||||
|
.then(() => process.exit(0))
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err)
|
||||||
|
process.exit(-1)
|
||||||
|
})
|
||||||
|
|
||||||
|
async function run () {
|
||||||
|
await initDatabaseModels(true)
|
||||||
|
|
||||||
|
const video = await VideoModel.loadByUUID(program['video'])
|
||||||
|
if (!video) throw new Error('Video not found.')
|
||||||
|
|
||||||
|
const dataInput = {
|
||||||
|
videoUUID: video.uuid,
|
||||||
|
isNewVideo: false
|
||||||
|
}
|
||||||
|
|
||||||
|
await JobQueue.Instance.init()
|
||||||
|
await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
|
||||||
|
console.log('Transcoding job for video %s created.', video.uuid)
|
||||||
|
}
|
|
@ -267,7 +267,8 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
|
||||||
if (CONFIG.TRANSCODING.ENABLED === true) {
|
if (CONFIG.TRANSCODING.ENABLED === true) {
|
||||||
// Put uuid because we don't have id auto incremented for now
|
// Put uuid because we don't have id auto incremented for now
|
||||||
const dataInput = {
|
const dataInput = {
|
||||||
videoUUID: videoCreated.uuid
|
videoUUID: videoCreated.uuid,
|
||||||
|
isNewVideo: true
|
||||||
}
|
}
|
||||||
|
|
||||||
await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
|
await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
|
||||||
|
|
|
@ -11,7 +11,8 @@ import { JobQueue } from '../job-queue'
|
||||||
|
|
||||||
export type VideoFilePayload = {
|
export type VideoFilePayload = {
|
||||||
videoUUID: string
|
videoUUID: string
|
||||||
resolution?: VideoResolution,
|
isNewVideo: boolean
|
||||||
|
resolution?: VideoResolution
|
||||||
isPortraitMode?: boolean
|
isPortraitMode?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ async function processVideoFile (job: kue.Job) {
|
||||||
await onVideoFileTranscoderSuccess(video)
|
await onVideoFileTranscoderSuccess(video)
|
||||||
} else {
|
} else {
|
||||||
await video.optimizeOriginalVideofile()
|
await video.optimizeOriginalVideofile()
|
||||||
await onVideoFileOptimizerSuccess(video)
|
await onVideoFileOptimizerSuccess(video, payload.isNewVideo)
|
||||||
}
|
}
|
||||||
|
|
||||||
return video
|
return video
|
||||||
|
@ -53,7 +54,7 @@ async function onVideoFileTranscoderSuccess (video: VideoModel) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onVideoFileOptimizerSuccess (video: VideoModel) {
|
async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boolean) {
|
||||||
if (video === undefined) return undefined
|
if (video === undefined) return undefined
|
||||||
|
|
||||||
// Maybe the video changed in database, refresh it
|
// Maybe the video changed in database, refresh it
|
||||||
|
@ -62,11 +63,15 @@ async function onVideoFileOptimizerSuccess (video: VideoModel) {
|
||||||
if (!videoDatabase) return undefined
|
if (!videoDatabase) return undefined
|
||||||
|
|
||||||
if (video.privacy !== VideoPrivacy.PRIVATE) {
|
if (video.privacy !== VideoPrivacy.PRIVATE) {
|
||||||
// Now we'll add the video's meta data to our followers
|
if (isNewVideo === true) {
|
||||||
await sequelizeTypescript.transaction(async t => {
|
// Now we'll add the video's meta data to our followers
|
||||||
await sendCreateVideo(video, t)
|
await sequelizeTypescript.transaction(async t => {
|
||||||
await shareVideoByServerAndChannel(video, t)
|
await sendCreateVideo(video, t)
|
||||||
})
|
await shareVideoByServerAndChannel(video, t)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await sendUpdateVideo(video, undefined)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { videoFileResolution } = await videoDatabase.getOriginalFileResolution()
|
const { videoFileResolution } = await videoDatabase.getOriginalFileResolution()
|
||||||
|
@ -84,7 +89,8 @@ async function onVideoFileOptimizerSuccess (video: VideoModel) {
|
||||||
for (const resolution of resolutionsEnabled) {
|
for (const resolution of resolutionsEnabled) {
|
||||||
const dataInput = {
|
const dataInput = {
|
||||||
videoUUID: videoDatabase.uuid,
|
videoUUID: videoDatabase.uuid,
|
||||||
resolution
|
resolution,
|
||||||
|
isNewVideo
|
||||||
}
|
}
|
||||||
|
|
||||||
const p = JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
|
const p = JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
|
||||||
|
|
96
server/tests/cli/create-transcoding-job.ts
Normal file
96
server/tests/cli/create-transcoding-job.ts
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
/* tslint:disable:no-unused-expression */
|
||||||
|
|
||||||
|
import 'mocha'
|
||||||
|
import * as chai from 'chai'
|
||||||
|
import { VideoDetails } from '../../../shared/models/videos'
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
|
import {
|
||||||
|
execCLI,
|
||||||
|
flushTests,
|
||||||
|
getEnvCli,
|
||||||
|
getVideosList,
|
||||||
|
killallServers,
|
||||||
|
parseTorrentVideo,
|
||||||
|
runServer,
|
||||||
|
ServerInfo,
|
||||||
|
setAccessTokensToServers,
|
||||||
|
uploadVideo,
|
||||||
|
wait,
|
||||||
|
getVideo, flushAndRunMultipleServers, doubleFollow
|
||||||
|
} from '../utils'
|
||||||
|
|
||||||
|
describe('Test create transcoding jobs', function () {
|
||||||
|
let servers: ServerInfo[] = []
|
||||||
|
let video2UUID: string
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
this.timeout(60000)
|
||||||
|
|
||||||
|
await flushTests()
|
||||||
|
|
||||||
|
// Run server 2 to have transcoding enabled
|
||||||
|
servers = await flushAndRunMultipleServers(2)
|
||||||
|
await setAccessTokensToServers(servers)
|
||||||
|
|
||||||
|
await doubleFollow(servers[0], servers[1])
|
||||||
|
|
||||||
|
// Upload two videos for our needs
|
||||||
|
await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
|
||||||
|
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' })
|
||||||
|
video2UUID = res.body.video.uuid
|
||||||
|
|
||||||
|
await wait(3000)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should have two video files on each server', async function () {
|
||||||
|
this.timeout(30000)
|
||||||
|
|
||||||
|
for (const server of servers) {
|
||||||
|
const res = await getVideosList(server.url)
|
||||||
|
const videos = res.body.data
|
||||||
|
expect(videos).to.have.lengthOf(2)
|
||||||
|
|
||||||
|
for (const video of videos) {
|
||||||
|
const res2 = await getVideo(server.url, video.uuid)
|
||||||
|
const videoDetail: VideoDetails = res2.body
|
||||||
|
expect(videoDetail.files).to.have.lengthOf(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should run a transcoding job on video 2', async function () {
|
||||||
|
this.timeout(60000)
|
||||||
|
|
||||||
|
const env = getEnvCli(servers[0])
|
||||||
|
await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
|
||||||
|
|
||||||
|
await wait(30000)
|
||||||
|
|
||||||
|
for (const server of servers) {
|
||||||
|
const res = await getVideosList(server.url)
|
||||||
|
const videos = res.body.data
|
||||||
|
expect(videos).to.have.lengthOf(2)
|
||||||
|
|
||||||
|
for (const video of videos) {
|
||||||
|
const res2 = await getVideo(server.url, video.uuid)
|
||||||
|
const videoDetail: VideoDetails = res2.body
|
||||||
|
|
||||||
|
if (video.uuid === video2UUID) {
|
||||||
|
expect(videoDetail.files).to.have.lengthOf(4)
|
||||||
|
} else {
|
||||||
|
expect(videoDetail.files).to.have.lengthOf(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
killallServers(servers)
|
||||||
|
|
||||||
|
// Keep the logs if the test failed
|
||||||
|
if (this['ok']) {
|
||||||
|
await flushTests()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
|
@ -1,3 +1,4 @@
|
||||||
// Order of the tests we want to execute
|
// Order of the tests we want to execute
|
||||||
|
import './create-transcoding-job'
|
||||||
import './reset-password'
|
import './reset-password'
|
||||||
import './update-host'
|
import './update-host'
|
||||||
|
|
Loading…
Add table
Reference in a new issue