aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-25 15:05:18 +0100
committerChocobozzz <me@florianbigard.com>2018-01-25 18:41:17 +0100
commit94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4 (patch)
tree32a9148e0e4567f0c4ffae0412cbed20b84e8873 /server/controllers
parentd765fafc3faf0db9818eb1a07161df1cb1bc0efa (diff)
downloadPeerTube-94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4.tar.gz
PeerTube-94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4.tar.zst
PeerTube-94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4.zip
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.
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/jobs.ts38
-rw-r--r--server/controllers/api/server/follows.ts2
-rw-r--r--server/controllers/api/videos/index.ts24
3 files changed, 46 insertions, 18 deletions
diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts
index de37dea39..132d110ad 100644
--- a/server/controllers/api/jobs.ts
+++ b/server/controllers/api/jobs.ts
@@ -1,22 +1,29 @@
1import * as express from 'express' 1import * as express from 'express'
2import { ResultList } from '../../../shared'
3import { Job, JobType, JobState } from '../../../shared/models'
2import { UserRight } from '../../../shared/models/users' 4import { UserRight } from '../../../shared/models/users'
3import { getFormattedObjects } from '../../helpers/utils' 5import { JobQueue } from '../../lib/job-queue'
4import { 6import {
5 asyncMiddleware, authenticate, ensureUserHasRight, jobsSortValidator, setDefaultPagination, 7 asyncMiddleware,
8 authenticate,
9 ensureUserHasRight,
10 jobsSortValidator,
11 setDefaultPagination,
6 setDefaultSort 12 setDefaultSort
7} from '../../middlewares' 13} from '../../middlewares'
8import { paginationValidator } from '../../middlewares/validators' 14import { paginationValidator } from '../../middlewares/validators'
9import { JobModel } from '../../models/job/job' 15import { listJobsValidator } from '../../middlewares/validators/jobs'
10 16
11const jobsRouter = express.Router() 17const jobsRouter = express.Router()
12 18
13jobsRouter.get('/', 19jobsRouter.get('/:state',
14 authenticate, 20 authenticate,
15 ensureUserHasRight(UserRight.MANAGE_JOBS), 21 ensureUserHasRight(UserRight.MANAGE_JOBS),
16 paginationValidator, 22 paginationValidator,
17 jobsSortValidator, 23 jobsSortValidator,
18 setDefaultSort, 24 setDefaultSort,
19 setDefaultPagination, 25 setDefaultPagination,
26 asyncMiddleware(listJobsValidator),
20 asyncMiddleware(listJobs) 27 asyncMiddleware(listJobs)
21) 28)
22 29
@@ -29,7 +36,26 @@ export {
29// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
30 37
31async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) { 38async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) {
32 const resultList = await JobModel.listForApi(req.query.start, req.query.count, req.query.sort) 39 const sort = req.query.sort === 'createdAt' ? 'asc' : 'desc'
40
41 const jobs = await JobQueue.Instance.listForApi(req.params.state, req.query.start, req.query.count, sort)
42 const total = await JobQueue.Instance.count(req.params.state)
43
44 const result: ResultList<any> = {
45 total,
46 data: jobs.map(j => formatJob(j.toJSON()))
47 }
48 return res.json(result)
49}
33 50
34 return res.json(getFormattedObjects(resultList.data, resultList.total)) 51function formatJob (job: any): Job {
52 return {
53 id: job.id,
54 state: job.state as JobState,
55 type: job.type as JobType,
56 data: job.data,
57 error: job.error,
58 createdAt: new Date(parseInt(job.created_at, 10)),
59 updatedAt: new Date(parseInt(job.updated_at, 10))
60 }
35} 61}
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts
index 506b9668e..bb8713e7a 100644
--- a/server/controllers/api/server/follows.ts
+++ b/server/controllers/api/server/follows.ts
@@ -123,7 +123,7 @@ function follow (fromActor: ActorModel, targetActor: ActorModel) {
123 actorFollow.ActorFollower = fromActor 123 actorFollow.ActorFollower = fromActor
124 124
125 // Send a notification to remote server 125 // Send a notification to remote server
126 await sendFollow(actorFollow, t) 126 await sendFollow(actorFollow)
127 }) 127 })
128} 128}
129 129
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 {
12} from '../../../initializers' 12} from '../../../initializers'
13import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' 13import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub'
14import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send' 14import { sendCreateVideo, sendCreateViewToOrigin, sendCreateViewToVideoFollowers, sendUpdateVideo } from '../../../lib/activitypub/send'
15import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler' 15import { JobQueue } from '../../../lib/job-queue'
16import { 16import {
17 asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setDefaultPagination, videosAddValidator, videosGetValidator, 17 asyncMiddleware, authenticate, paginationValidator, setDefaultSort, setDefaultPagination, videosAddValidator, videosGetValidator,
18 videosRemoveValidator, videosSearchValidator, videosSortValidator, videosUpdateValidator 18 videosRemoveValidator, videosSearchValidator, videosSortValidator, videosUpdateValidator
@@ -176,18 +176,9 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
176 ) 176 )
177 await Promise.all(tasks) 177 await Promise.all(tasks)
178 178
179 return sequelizeTypescript.transaction(async t => { 179 const videoCreated = await sequelizeTypescript.transaction(async t => {
180 const sequelizeOptions = { transaction: t } 180 const sequelizeOptions = { transaction: t }
181 181
182 if (CONFIG.TRANSCODING.ENABLED === true) {
183 // Put uuid because we don't have id auto incremented for now
184 const dataInput = {
185 videoUUID: video.uuid
186 }
187
188 await transcodingJobScheduler.createJob(t, 'videoFileOptimizer', dataInput)
189 }
190
191 const videoCreated = await video.save(sequelizeOptions) 182 const videoCreated = await video.save(sequelizeOptions)
192 // Do not forget to add video channel information to the created video 183 // Do not forget to add video channel information to the created video
193 videoCreated.VideoChannel = res.locals.videoChannel 184 videoCreated.VideoChannel = res.locals.videoChannel
@@ -216,6 +207,17 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
216 207
217 return videoCreated 208 return videoCreated
218 }) 209 })
210
211 if (CONFIG.TRANSCODING.ENABLED === true) {
212 // Put uuid because we don't have id auto incremented for now
213 const dataInput = {
214 videoUUID: videoCreated.uuid
215 }
216
217 await JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
218 }
219
220 return videoCreated
219} 221}
220 222
221async function updateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { 223async function updateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {