@@ -22,6 +22,7 @@ import { MongoQuery } from '@sofie-automation/corelib/dist/mongo'
2222import { UserActionsLog } from '../collections'
2323import { MetricsCounter } from '@sofie-automation/corelib/dist/prometheus'
2424import { isInTestWrite } from '../security/securityVerify'
25+ import { QueueJobOptions } from '@sofie-automation/job-worker/dist/jobs'
2526
2627const FREEZE_LIMIT = 1000 // how long to wait for a response to a Ping
2728const RESTART_TIMEOUT = 30000 // how long to wait for a restart to complete before throwing an error
@@ -51,6 +52,8 @@ const metricsQueueErrorsCounter = new MetricsCounter({
5152
5253interface JobQueue {
5354 jobs : Array < JobEntry | null >
55+ // lowPriorityJobs: Array<JobEntry>
56+
5457 /** Notify that there is a job waiting (aka worker is long-polling) */
5558 notifyWorker : ManualPromise < void > | null
5659
@@ -177,18 +180,27 @@ async function interruptJobStream(queueName: string): Promise<void> {
177180 queue . jobs . unshift ( null )
178181 }
179182}
180- async function queueJobWithoutResult ( queueName : string , jobName : string , jobData : unknown ) : Promise < void > {
181- queueJobInner ( queueName , {
182- spec : {
183- id : getRandomString ( ) ,
184- name : jobName ,
185- data : jobData ,
183+ async function queueJobWithoutResult (
184+ queueName : string ,
185+ jobName : string ,
186+ jobData : unknown ,
187+ options : QueueJobOptions | undefined
188+ ) : Promise < void > {
189+ queueJobInner (
190+ queueName ,
191+ {
192+ spec : {
193+ id : getRandomString ( ) ,
194+ name : jobName ,
195+ data : jobData ,
196+ } ,
197+ completionHandler : null ,
186198 } ,
187- completionHandler : null ,
188- } )
199+ options ?? { }
200+ )
189201}
190202
191- function queueJobInner ( queueName : string , jobToQueue : JobEntry ) : void {
203+ function queueJobInner ( queueName : string , jobToQueue : JobEntry , options : QueueJobOptions ) : void {
192204 // Put the job at the end of the queue:
193205 const queue = getOrCreateQueue ( queueName )
194206 queue . jobs . push ( jobToQueue )
@@ -212,13 +224,22 @@ function queueJobInner(queueName: string, jobToQueue: JobEntry): void {
212224 }
213225}
214226
215- function queueJobAndWrapResult < TRes > ( queueName : string , job : JobSpec , now : Time ) : WorkerJob < TRes > {
227+ function queueJobAndWrapResult < TRes > (
228+ queueName : string ,
229+ job : JobSpec ,
230+ now : Time ,
231+ options : QueueJobOptions | undefined
232+ ) : WorkerJob < TRes > {
216233 const { result, completionHandler } = generateCompletionHandler < TRes > ( job . id , now )
217234
218- queueJobInner ( queueName , {
219- spec : job ,
220- completionHandler : completionHandler ,
221- } )
235+ queueJobInner (
236+ queueName ,
237+ {
238+ spec : job ,
239+ completionHandler : completionHandler ,
240+ } ,
241+ options ?? { }
242+ )
222243
223244 return result
224245}
@@ -413,7 +434,8 @@ export async function QueueForceClearAllCaches(studioIds: StudioId[]): Promise<v
413434 name : FORCE_CLEAR_CACHES_JOB ,
414435 data : undefined ,
415436 } ,
416- now
437+ now ,
438+ { }
417439 )
418440 )
419441
@@ -426,7 +448,8 @@ export async function QueueForceClearAllCaches(studioIds: StudioId[]): Promise<v
426448 name : FORCE_CLEAR_CACHES_JOB ,
427449 data : undefined ,
428450 } ,
429- now
451+ now ,
452+ { }
430453 )
431454 )
432455
@@ -439,7 +462,8 @@ export async function QueueForceClearAllCaches(studioIds: StudioId[]): Promise<v
439462 name : FORCE_CLEAR_CACHES_JOB ,
440463 data : undefined ,
441464 } ,
442- now
465+ now ,
466+ { }
443467 )
444468 )
445469 }
@@ -458,7 +482,8 @@ export async function QueueForceClearAllCaches(studioIds: StudioId[]): Promise<v
458482export async function QueueStudioJob < T extends keyof StudioJobFunc > (
459483 jobName : T ,
460484 studioId : StudioId ,
461- jobParameters : Parameters < StudioJobFunc [ T ] > [ 0 ]
485+ jobParameters : Parameters < StudioJobFunc [ T ] > [ 0 ] ,
486+ options ?: QueueJobOptions
462487) : Promise < WorkerJob < ReturnType < StudioJobFunc [ T ] > > > {
463488 if ( isInTestWrite ( ) ) throw new Meteor . Error ( 404 , 'Should not be reachable during startup tests' )
464489 if ( ! studioId ) throw new Meteor . Error ( 500 , 'Missing studioId' )
@@ -471,7 +496,8 @@ export async function QueueStudioJob<T extends keyof StudioJobFunc>(
471496 name : jobName ,
472497 data : jobParameters ,
473498 } ,
474- now
499+ now ,
500+ options
475501 )
476502}
477503
0 commit comments