diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 63892e8..bf28e3a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [14, 16, 17] + node-version: [14, 16, 18] mongodb-version: [3.6, 4.4, 5.0] steps: - name: Git checkout diff --git a/src/Job.ts b/src/Job.ts index f69805e..c627ba2 100644 --- a/src/Job.ts +++ b/src/Job.ts @@ -9,9 +9,6 @@ import { IJobParameters, datefields, TJobDatefield } from './types/JobParameters import { JobPriority, parsePriority } from './utils/priority'; import { computeFromInterval, computeFromRepeatAt } from './utils/nextRunAt'; -const controller = new AbortController(); -const { signal } = controller; - const log = debug('agenda:job'); /** @@ -376,9 +373,18 @@ export class Job { Job.functionLocationCache[this.attrs.name] = location; } // console.log('location', location); + let controller: AbortController | undefined; + let signal: AbortSignal | undefined; + if (typeof AbortController !== 'undefined') { + controller = new AbortController(); + ({ signal } = controller); + } else { + console.warn('AbortController not supported!'); + } await new Promise((resolve, reject) => { let stillRunning = true; + const child = fork( forkHelper.path, [this.attrs.name, this.attrs._id!.toString(), location], @@ -410,7 +416,7 @@ export class Job { const checkCancel = () => setTimeout(() => { if (this.canceled) { - controller.abort(); // Stops the child process + controller?.abort(); // Stops the child process } else if (stillRunning) { setTimeout(checkCancel, 10000); }