]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/job-queue.ts
Support progress for ffmpeg tasks
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / job-queue.ts
index 8d97434ac59b954d33510dd32780a051516ec955..5d0b797b0ca157aab24e72cb8d0750ce5d5d2f2d 100644 (file)
@@ -1,4 +1,6 @@
 import * as Bull from 'bull'
+import { jobStates } from '@server/helpers/custom-validators/jobs'
+import { processVideoRedundancy } from '@server/lib/job-queue/handlers/video-redundancy'
 import {
   ActivitypubFollowPayload,
   ActivitypubHttpBroadcastPayload,
@@ -15,20 +17,19 @@ import {
   VideoTranscodingPayload
 } from '../../../shared/models'
 import { logger } from '../../helpers/logger'
-import { Redis } from '../redis'
 import { JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_TTL, REPEAT_JOBS, WEBSERVER } from '../../initializers/constants'
+import { Redis } from '../redis'
+import { processActivityPubFollow } from './handlers/activitypub-follow'
 import { processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast'
 import { processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher'
 import { processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast'
-import { processEmail } from './handlers/email'
-import { processVideoTranscoding } from './handlers/video-transcoding'
-import { processActivityPubFollow } from './handlers/activitypub-follow'
-import { processVideoImport } from './handlers/video-import'
-import { processVideosViews } from './handlers/video-views'
 import { refreshAPObject } from './handlers/activitypub-refresher'
+import { processEmail } from './handlers/email'
 import { processVideoFileImport } from './handlers/video-file-import'
-import { processVideoRedundancy } from '@server/lib/job-queue/handlers/video-redundancy'
+import { processVideoImport } from './handlers/video-import'
 import { processVideoLiveEnding } from './handlers/video-live-ending'
+import { processVideoTranscoding } from './handlers/video-transcoding'
+import { processVideosViews } from './handlers/video-views'
 
 type CreateJobArgument =
   { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } |
@@ -154,13 +155,15 @@ class JobQueue {
   }
 
   async listForApi (options: {
-    state: JobState
+    state?: JobState
     start: number
     count: number
     asc?: boolean
     jobType: JobType
   }): Promise<Bull.Job[]> {
     const { state, start, count, asc, jobType } = options
+
+    const states = state ? [ state ] : jobStates
     let results: Bull.Job[] = []
 
     const filteredJobTypes = this.filterJobTypes(jobType)
@@ -172,7 +175,7 @@ class JobQueue {
         continue
       }
 
-      const jobs = await queue.getJobs([ state ], 0, start + count, asc)
+      const jobs = await queue.getJobs(states, 0, start + count, asc)
       results = results.concat(jobs)
     }
 
@@ -189,6 +192,7 @@ class JobQueue {
   }
 
   async count (state: JobState, jobType?: JobType): Promise<number> {
+    const states = state ? [ state ] : jobStates
     let total = 0
 
     const filteredJobTypes = this.filterJobTypes(jobType)
@@ -202,7 +206,9 @@ class JobQueue {
 
       const counts = await queue.getJobCounts()
 
-      total += counts[state]
+      for (const s of states) {
+        total += counts[s]
+      }
     }
 
     return total