]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/job-queue.ts
prevent multiple post-process triggering of upload-resumable (#4175)
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / job-queue.ts
index 42e8347b1f663650c5aed7042c5e02cbd1b9ffcc..53d6b6a9cfb8a34c46ee2f9b660f0aa388c6aea5 100644 (file)
@@ -1,4 +1,4 @@
-import * as Bull from 'bull'
+import Bull, { Job, JobOptions, Queue } from 'bull'
 import { jobStates } from '@server/helpers/custom-validators/jobs'
 import { CONFIG } from '@server/initializers/config'
 import { processVideoRedundancy } from '@server/lib/job-queue/handlers/video-redundancy'
@@ -8,9 +8,11 @@ import {
   ActivitypubHttpFetcherPayload,
   ActivitypubHttpUnicastPayload,
   ActorKeysPayload,
+  DeleteResumableUploadMetaFilePayload,
   EmailPayload,
   JobState,
   JobType,
+  MoveObjectStoragePayload,
   RefreshPayload,
   VideoFileImportPayload,
   VideoImportPayload,
@@ -29,6 +31,7 @@ import { processActivityPubHttpUnicast } from './handlers/activitypub-http-unica
 import { refreshAPObject } from './handlers/activitypub-refresher'
 import { processActorKeys } from './handlers/actor-keys'
 import { processEmail } from './handlers/email'
+import { processMoveToObjectStorage } from './handlers/move-to-object-storage'
 import { processVideoFileImport } from './handlers/video-file-import'
 import { processVideoImport } from './handlers/video-import'
 import { processVideoLiveEnding } from './handlers/video-live-ending'
@@ -49,14 +52,16 @@ type CreateJobArgument =
   { type: 'videos-views', payload: {} } |
   { type: 'video-live-ending', payload: VideoLiveEndingPayload } |
   { type: 'actor-keys', payload: ActorKeysPayload } |
-  { type: 'video-redundancy', payload: VideoRedundancyPayload }
+  { type: 'video-redundancy', payload: VideoRedundancyPayload } |
+  { type: 'delete-resumable-upload-meta-file', payload: DeleteResumableUploadMetaFilePayload } |
+  { type: 'move-to-object-storage', payload: MoveObjectStoragePayload }
 
-type CreateJobOptions = {
+export type CreateJobOptions = {
   delay?: number
   priority?: number
 }
 
-const handlers: { [id in JobType]: (job: Bull.Job) => Promise<any> } = {
+const handlers: { [id in JobType]: (job: Job) => Promise<any> } = {
   'activitypub-http-broadcast': processActivityPubHttpBroadcast,
   'activitypub-http-unicast': processActivityPubHttpUnicast,
   'activitypub-http-fetcher': processActivityPubHttpFetcher,
@@ -70,7 +75,8 @@ const handlers: { [id in JobType]: (job: Bull.Job) => Promise<any> } = {
   'activitypub-refresher': refreshAPObject,
   'video-live-ending': processVideoLiveEnding,
   'actor-keys': processActorKeys,
-  'video-redundancy': processVideoRedundancy
+  'video-redundancy': processVideoRedundancy,
+  'move-to-object-storage': processMoveToObjectStorage
 }
 
 const jobTypes: JobType[] = [
@@ -87,14 +93,15 @@ const jobTypes: JobType[] = [
   'activitypub-refresher',
   'video-redundancy',
   'actor-keys',
-  'video-live-ending'
+  'video-live-ending',
+  'move-to-object-storage'
 ]
 
 class JobQueue {
 
   private static instance: JobQueue
 
-  private queues: { [id in JobType]?: Bull.Queue } = {}
+  private queues: { [id in JobType]?: Queue } = {}
   private initialized = false
   private jobRedisPrefix: string
 
@@ -155,7 +162,7 @@ class JobQueue {
       return
     }
 
-    const jobArgs: Bull.JobOptions = {
+    const jobArgs: JobOptions = {
       backoff: { delay: 60 * 1000, type: 'exponential' },
       attempts: JOB_ATTEMPTS[obj.type],
       timeout: JOB_TTL[obj.type],
@@ -172,11 +179,11 @@ class JobQueue {
     count: number
     asc?: boolean
     jobType: JobType
-  }): Promise<Bull.Job[]> {
+  }): Promise<Job[]> {
     const { state, start, count, asc, jobType } = options
 
     const states = state ? [ state ] : jobStates
-    let results: Bull.Job[] = []
+    let results: Job[] = []
 
     const filteredJobTypes = this.filterJobTypes(jobType)