@@ -9,9 +9,6 @@ import { IJobParameters, datefields, TJobDatefield } from './types/JobParameters
9
9
import { JobPriority , parsePriority } from './utils/priority' ;
10
10
import { computeFromInterval , computeFromRepeatAt } from './utils/nextRunAt' ;
11
11
12
- const controller = new AbortController ( ) ;
13
- const { signal } = controller ;
14
-
15
12
const log = debug ( 'agenda:job' ) ;
16
13
17
14
/**
@@ -376,9 +373,18 @@ export class Job<DATA = unknown | void> {
376
373
Job . functionLocationCache [ this . attrs . name ] = location ;
377
374
}
378
375
// console.log('location', location);
376
+ let controller : AbortController | undefined ;
377
+ let signal : AbortSignal | undefined ;
378
+ if ( typeof AbortController !== 'undefined' ) {
379
+ controller = new AbortController ( ) ;
380
+ ( { signal } = controller ) ;
381
+ } else {
382
+ console . warn ( 'AbortController not supported!' ) ;
383
+ }
379
384
380
385
await new Promise < void > ( ( resolve , reject ) => {
381
386
let stillRunning = true ;
387
+
382
388
const child = fork (
383
389
forkHelper . path ,
384
390
[ this . attrs . name , this . attrs . _id ! . toString ( ) , location ] ,
@@ -410,7 +416,7 @@ export class Job<DATA = unknown | void> {
410
416
const checkCancel = ( ) =>
411
417
setTimeout ( ( ) => {
412
418
if ( this . canceled ) {
413
- controller . abort ( ) ; // Stops the child process
419
+ controller ? .abort ( ) ; // Stops the child process
414
420
} else if ( stillRunning ) {
415
421
setTimeout ( checkCancel , 10000 ) ;
416
422
}
0 commit comments