RefreshPayload,
VideoFileImportPayload,
VideoImportPayload,
+ VideoLiveEndingPayload,
VideoRedundancyPayload,
VideoTranscodingPayload
} from '../../../shared/models'
import { refreshAPObject } from './handlers/activitypub-refresher'
import { processVideoFileImport } from './handlers/video-file-import'
import { processVideoRedundancy } from '@server/lib/job-queue/handlers/video-redundancy'
+import { processVideoLiveEnding } from './handlers/video-live-ending'
type CreateJobArgument =
{ type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } |
{ type: 'video-import', payload: VideoImportPayload } |
{ type: 'activitypub-refresher', payload: RefreshPayload } |
{ type: 'videos-views', payload: {} } |
+ { type: 'video-live-ending', payload: VideoLiveEndingPayload } |
{ type: 'video-redundancy', payload: VideoRedundancyPayload }
+type CreateJobOptions = {
+ delay?: number
+}
+
const handlers: { [id in JobType]: (job: Bull.Job) => Promise<any> } = {
'activitypub-http-broadcast': processActivityPubHttpBroadcast,
'activitypub-http-unicast': processActivityPubHttpUnicast,
'video-import': processVideoImport,
'videos-views': processVideosViews,
'activitypub-refresher': refreshAPObject,
+ 'video-live-ending': processVideoLiveEnding,
'video-redundancy': processVideoRedundancy
}
'video-import',
'videos-views',
'activitypub-refresher',
- 'video-redundancy'
+ 'video-redundancy',
+ 'video-live-ending'
]
class JobQueue {
}
}
- createJob (obj: CreateJobArgument): void {
- this.createJobWithPromise(obj)
+ createJob (obj: CreateJobArgument, options: CreateJobOptions = {}): void {
+ this.createJobWithPromise(obj, options)
.catch(err => logger.error('Cannot create job.', { err, obj }))
}
- createJobWithPromise (obj: CreateJobArgument) {
+ createJobWithPromise (obj: CreateJobArgument, options: CreateJobOptions = {}) {
const queue = this.queues[obj.type]
if (queue === undefined) {
logger.error('Unknown queue %s: cannot create job.', obj.type)
const jobArgs: Bull.JobOptions = {
backoff: { delay: 60 * 1000, type: 'exponential' },
attempts: JOB_ATTEMPTS[obj.type],
- timeout: JOB_TTL[obj.type]
+ timeout: JOB_TTL[obj.type],
+ delay: options.delay
}
return queue.add(obj.payload, jobArgs)
}
async listForApi (options: {
- state: JobState
+ state: JobState | JobState[]
start: number
count: number
asc?: boolean
jobType: JobType
}): Promise<Bull.Job[]> {
- const { state, start, count, asc, jobType } = options
+ const { state = Array.isArray(options.state) ? options.state : [ options.state ], start, count, asc, jobType } = options
let results: Bull.Job[] = []
const filteredJobTypes = this.filterJobTypes(jobType)
continue
}
- const jobs = await queue.getJobs([ state ], 0, start + count, asc)
+ const jobs = await queue.getJobs(state as Bull.JobStatus[], 0, start + count, asc)
results = results.concat(jobs)
}
return results.slice(start, start + count)
}
- async count (state: JobState, jobType?: JobType): Promise<number> {
+ async count (state: JobState | JobState[], jobType?: JobType): Promise<number> {
+ const states = Array.isArray(state) ? state : [ state ]
let total = 0
const filteredJobTypes = this.filterJobTypes(jobType)
const counts = await queue.getJobCounts()
- total += counts[state]
+ for (const s of states) {
+ total += counts[s]
+ }
}
return total