@sidequest/engine 1.6.2 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine.cjs +5 -1
- package/dist/engine.cjs.map +1 -1
- package/dist/engine.d.ts +12 -0
- package/dist/engine.js +5 -1
- package/dist/engine.js.map +1 -1
- package/dist/execution/executor-manager.cjs +3 -0
- package/dist/execution/executor-manager.cjs.map +1 -1
- package/dist/execution/executor-manager.js +3 -0
- package/dist/execution/executor-manager.js.map +1 -1
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/job/cron-registry.cjs +86 -0
- package/dist/job/cron-registry.cjs.map +1 -0
- package/dist/job/cron-registry.d.ts +39 -0
- package/dist/job/cron-registry.js +84 -0
- package/dist/job/cron-registry.js.map +1 -0
- package/dist/job/job-builder.cjs +24 -5
- package/dist/job/job-builder.cjs.map +1 -1
- package/dist/job/job-builder.d.ts +17 -15
- package/dist/job/job-builder.js +24 -5
- package/dist/job/job-builder.js.map +1 -1
- package/dist/shared-runner/manual-loader.cjs +62 -0
- package/dist/shared-runner/manual-loader.cjs.map +1 -0
- package/dist/shared-runner/manual-loader.d.ts +28 -0
- package/dist/shared-runner/manual-loader.js +59 -0
- package/dist/shared-runner/manual-loader.js.map +1 -0
- package/dist/shared-runner/runner.cjs +20 -2
- package/dist/shared-runner/runner.cjs.map +1 -1
- package/dist/shared-runner/runner.js +21 -3
- package/dist/shared-runner/runner.js.map +1 -1
- package/package.json +6 -6
package/dist/engine.cjs
CHANGED
|
@@ -7,6 +7,7 @@ var os = require('os');
|
|
|
7
7
|
var util = require('util');
|
|
8
8
|
var constants$1 = require('./constants.cjs');
|
|
9
9
|
var constants = require('./job/constants.cjs');
|
|
10
|
+
var cronRegistry = require('./job/cron-registry.cjs');
|
|
10
11
|
var jobBuilder = require('./job/job-builder.cjs');
|
|
11
12
|
var grantQueueConfig = require('./queue/grant-queue-config.cjs');
|
|
12
13
|
var shutdown = require('./utils/shutdown.cjs');
|
|
@@ -81,6 +82,7 @@ class Engine {
|
|
|
81
82
|
priority: config?.queueDefaults?.priority ?? backend.QUEUE_FALLBACK.priority,
|
|
82
83
|
state: config?.queueDefaults?.state ?? backend.QUEUE_FALLBACK.state,
|
|
83
84
|
},
|
|
85
|
+
manualJobResolution: config?.manualJobResolution ?? false,
|
|
84
86
|
};
|
|
85
87
|
if (this.config.maxConcurrentJobs !== undefined && this.config.maxConcurrentJobs < 1) {
|
|
86
88
|
throw new Error(`Invalid "maxConcurrentJobs" value: must be at least 1.`);
|
|
@@ -161,6 +163,8 @@ class Engine {
|
|
|
161
163
|
if (!this.shuttingDown) {
|
|
162
164
|
this.shuttingDown = true;
|
|
163
165
|
core.logger("Engine").debug("Closing Sidequest engine...");
|
|
166
|
+
// Stop all scheduled cron jobs first
|
|
167
|
+
await cronRegistry.ScheduledJobRegistry.stopAll();
|
|
164
168
|
if (this.mainWorker) {
|
|
165
169
|
const promise = new Promise((resolve) => {
|
|
166
170
|
this.mainWorker.on("exit", resolve);
|
|
@@ -202,7 +206,7 @@ class Engine {
|
|
|
202
206
|
// We need to do this check again because available at is a getter. It needs to be set at job creation time.
|
|
203
207
|
// If not set, it will use the fallback value which is outdated from config.
|
|
204
208
|
availableAt: this.config.jobDefaults.availableAt ?? constants.JOB_BUILDER_FALLBACK.availableAt,
|
|
205
|
-
});
|
|
209
|
+
}, this.config.manualJobResolution);
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
|
package/dist/engine.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.cjs","sources":["../src/engine.ts"],"sourcesContent":[null],"names":["logger","cpus","MISC_FALLBACK","JOB_BUILDER_FALLBACK","QUEUE_FALLBACK","inspect","configureLogger","LazyBackend","grantQueueConfig","fork","DEFAULT_WORKER_PATH","gracefulShutdown","clearGracefulShutdown","JobBuilder"],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.cjs","sources":["../src/engine.ts"],"sourcesContent":[null],"names":["logger","cpus","MISC_FALLBACK","JOB_BUILDER_FALLBACK","QUEUE_FALLBACK","inspect","configureLogger","LazyBackend","grantQueueConfig","fork","DEFAULT_WORKER_PATH","gracefulShutdown","ScheduledJobRegistry","clearGracefulShutdown","JobBuilder"],"mappings":";;;;;;;;;;;;;;AAqFA;;AAEG;MACU,MAAM,CAAA;AACjB;;;AAGG;AACK,IAAA,OAAO;AAEf;;;;AAIG;AACK,IAAA,MAAM;AAEd;;;AAGG;AACK,IAAA,UAAU;AAElB;;;AAGG;IACK,YAAY,GAAG,KAAK;AAE5B;;;;AAIG;IACH,MAAM,SAAS,CAAC,MAAqB,EAAA;AACnC,QAAA,IAAI,IAAI,CAAC,MAAM,EAAE;YACfA,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,8BAA8B,CAAC;YACtD,OAAO,IAAI,CAAC,MAAM;QACpB;QACA,IAAI,CAAC,MAAM,GAAG;AACZ,YAAA,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,EAAE;AAC5B,YAAA,OAAO,EAAE;AACP,gBAAA,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,2BAA2B;AAC9D,gBAAA,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,oBAAoB;AACxD,aAAA;AACD,YAAA,8BAA8B,EAAE,MAAM,EAAE,8BAA8B,IAAI,EAAE;AAC5E,YAAA,4BAA4B,EAAE,MAAM,EAAE,4BAA4B,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;AAC9F,YAAA,2BAA2B,EAAE,MAAM,EAAE,2BAA2B,IAAI,EAAE;AACtE,YAAA,iBAAiB,EAAE,MAAM,EAAE,iBAAiB,IAAI,EAAE;AAClD,YAAA,aAAa,EAAE,MAAM,EAAE,aAAa,IAAI,KAAK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CAAC,OAAO,GAAG,SAAS;AACxB,YAAA,IAAI,CAAC,UAAU,GAAG,SAAS;;;AAG3B,YAAAa,8BAAqB,EAAE;YACvBb,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC;AAClD,YAAA,IAAI,CAAC,YAAY,GAAG,KAAK;QAC3B;IACF;AAEA;;;;AAIG;AACH,IAAA,KAAK,CAAyB,QAAW,EAAA;QACvC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;AACjC,YAAA,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC;QAC5F;AACA,QAAA,IAAI,IAAI,CAAC,YAAY,EAAE;AACrB,YAAA,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC;QAC/D;AACA,QAAAA,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,wBAAA,EAA2B,QAAQ,CAAC,IAAI,CAAA,CAAE,CAAC;QAClE,OAAO,IAAIc,qBAAU,CACnB,IAAI,CAAC,OAAO,EACZ,QAAQ,EACR;AACE,YAAA,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW;;;YAG1B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,IAAIX,8BAAoB,CAAC,WAAY;AACtF,SAAA,EACD,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAChC;IACH;AACD;;;;"}
|
package/dist/engine.d.ts
CHANGED
|
@@ -51,6 +51,18 @@ interface EngineConfig {
|
|
|
51
51
|
* @see {@link QueueDefaults} for more details
|
|
52
52
|
*/
|
|
53
53
|
queueDefaults?: QueueDefaults;
|
|
54
|
+
/**
|
|
55
|
+
* If true, job scripts will NOT be automatically resolved by the engine.
|
|
56
|
+
* In this case, you need to create a `sidequest.jobs.js` file at the root of your project
|
|
57
|
+
* (and at the root of any other project that uses Sidequest, like a worker) that imports and
|
|
58
|
+
* exports all job classes.
|
|
59
|
+
*
|
|
60
|
+
* This allows you to control exactly which job classes are available to Sidequest,
|
|
61
|
+
* and can also solve issues with module resolution in certain environments.
|
|
62
|
+
*
|
|
63
|
+
* Defaults to `false`.
|
|
64
|
+
*/
|
|
65
|
+
manualJobResolution?: boolean;
|
|
54
66
|
}
|
|
55
67
|
/**
|
|
56
68
|
* Non-nullable version of the EngineConfig type.
|
package/dist/engine.js
CHANGED
|
@@ -5,6 +5,7 @@ import { cpus } from 'os';
|
|
|
5
5
|
import { inspect } from 'util';
|
|
6
6
|
import { DEFAULT_WORKER_PATH } from './constants.js';
|
|
7
7
|
import { JOB_BUILDER_FALLBACK } from './job/constants.js';
|
|
8
|
+
import { ScheduledJobRegistry } from './job/cron-registry.js';
|
|
8
9
|
import { JobBuilder } from './job/job-builder.js';
|
|
9
10
|
import { grantQueueConfig } from './queue/grant-queue-config.js';
|
|
10
11
|
import { gracefulShutdown, clearGracefulShutdown } from './utils/shutdown.js';
|
|
@@ -79,6 +80,7 @@ class Engine {
|
|
|
79
80
|
priority: config?.queueDefaults?.priority ?? QUEUE_FALLBACK.priority,
|
|
80
81
|
state: config?.queueDefaults?.state ?? QUEUE_FALLBACK.state,
|
|
81
82
|
},
|
|
83
|
+
manualJobResolution: config?.manualJobResolution ?? false,
|
|
82
84
|
};
|
|
83
85
|
if (this.config.maxConcurrentJobs !== undefined && this.config.maxConcurrentJobs < 1) {
|
|
84
86
|
throw new Error(`Invalid "maxConcurrentJobs" value: must be at least 1.`);
|
|
@@ -159,6 +161,8 @@ class Engine {
|
|
|
159
161
|
if (!this.shuttingDown) {
|
|
160
162
|
this.shuttingDown = true;
|
|
161
163
|
logger("Engine").debug("Closing Sidequest engine...");
|
|
164
|
+
// Stop all scheduled cron jobs first
|
|
165
|
+
await ScheduledJobRegistry.stopAll();
|
|
162
166
|
if (this.mainWorker) {
|
|
163
167
|
const promise = new Promise((resolve) => {
|
|
164
168
|
this.mainWorker.on("exit", resolve);
|
|
@@ -200,7 +204,7 @@ class Engine {
|
|
|
200
204
|
// We need to do this check again because available at is a getter. It needs to be set at job creation time.
|
|
201
205
|
// If not set, it will use the fallback value which is outdated from config.
|
|
202
206
|
availableAt: this.config.jobDefaults.availableAt ?? JOB_BUILDER_FALLBACK.availableAt,
|
|
203
|
-
});
|
|
207
|
+
}, this.config.manualJobResolution);
|
|
204
208
|
}
|
|
205
209
|
}
|
|
206
210
|
|
package/dist/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sources":["../src/engine.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.js","sources":["../src/engine.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;AAqFA;;AAEG;MACU,MAAM,CAAA;AACjB;;;AAGG;AACK,IAAA,OAAO;AAEf;;;;AAIG;AACK,IAAA,MAAM;AAEd;;;AAGG;AACK,IAAA,UAAU;AAElB;;;AAGG;IACK,YAAY,GAAG,KAAK;AAE5B;;;;AAIG;IACH,MAAM,SAAS,CAAC,MAAqB,EAAA;AACnC,QAAA,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,8BAA8B,CAAC;YACtD,OAAO,IAAI,CAAC,MAAM;QACpB;QACA,IAAI,CAAC,MAAM,GAAG;AACZ,YAAA,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,EAAE;AAC5B,YAAA,OAAO,EAAE;AACP,gBAAA,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,2BAA2B;AAC9D,gBAAA,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,oBAAoB;AACxD,aAAA;AACD,YAAA,8BAA8B,EAAE,MAAM,EAAE,8BAA8B,IAAI,EAAE;AAC5E,YAAA,4BAA4B,EAAE,MAAM,EAAE,4BAA4B,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;AAC9F,YAAA,2BA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CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC;YACzD;AACA,YAAA,IAAI,CAAC,MAAM,GAAG,SAAS;AACvB,YAAA,IAAI,CAAC,OAAO,GAAG,SAAS;AACxB,YAAA,IAAI,CAAC,UAAU,GAAG,SAAS;;;AAG3B,YAAA,qBAAqB,EAAE;YACvB,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC;AAClD,YAAA,IAAI,CAAC,YAAY,GAAG,KAAK;QAC3B;IACF;AAEA;;;;AAIG;AACH,IAAA,KAAK,CAAyB,QAAW,EAAA;QACvC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;AACjC,YAAA,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC;QAC5F;AACA,QAAA,IAAI,IAAI,CAAC,YAAY,EAAE;AACrB,YAAA,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC;QAC/D;AACA,QAAA,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,wBAAA,EAA2B,QAAQ,CAAC,IAAI,CAAA,CAAE,CAAC;QAClE,OAAO,IAAI,UAAU,CACnB,IAAI,CAAC,OAAO,EACZ,QAAQ,EACR;AACE,YAAA,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW;;;YAG1B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,IAAI,oBAAoB,CAAC,WAAY;AACtF,SAAA,EACD,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAChC;IACH;AACD;;;;"}
|
|
@@ -4,6 +4,9 @@ var core = require('@sidequest/core');
|
|
|
4
4
|
var EventEmitter = require('events');
|
|
5
5
|
var util = require('util');
|
|
6
6
|
var jobTransitioner = require('../job/job-transitioner.cjs');
|
|
7
|
+
require('node:fs');
|
|
8
|
+
require('node:path');
|
|
9
|
+
require('node:url');
|
|
7
10
|
var runnerPool = require('../shared-runner/runner-pool.cjs');
|
|
8
11
|
|
|
9
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor-manager.cjs","sources":["../../src/execution/executor-manager.ts"],"sourcesContent":[null],"names":["RunnerPool","logger","JobTransitioner","SnoozeTransition","RunTransition","RetryTransition","inspect","JobTransitionFactory"],"mappings":"
|
|
1
|
+
{"version":3,"file":"executor-manager.cjs","sources":["../../src/execution/executor-manager.ts"],"sourcesContent":[null],"names":["RunnerPool","logger","JobTransitioner","SnoozeTransition","RunTransition","RetryTransition","inspect","JobTransitionFactory"],"mappings":";;;;;;;;;;;AAgBA;;AAEG;MACU,eAAe,CAAA;AAWhB,IAAA,OAAA;AACA,IAAA,aAAA;AAXF,IAAA,aAAa;AACb,IAAA,UAAU;AACV,IAAA,UAAU;AAElB;;;;AAIG;IACH,WAAA,CACU,OAAgB,EAChB,aAAsC,EAAA;QADtC,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,aAAa,GAAb,aAAa;AAErB,QAAA,IAAI,CAAC,aAAa,GAAG,EAAE;AACvB,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAIA,qBAAU,CAAC,IAAI,CAAC,aAAa,CAAC;IACtD;AAEA;;;;AAIG;AACH,IAAA,qBAAqB,CAAC,WAAwB,EAAA;QAC5C,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE;YACzC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE;QAClD;QACA,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC;AACvD,QAAA,MAAM,KAAK,GAAG,WAAW,CAAC,WAAW,IAAI,EAAE;AAE3C,QAAA,MAAM,cAAc,GAAG,KAAK,GAAG,UAAU,CAAC,IAAI;AAC9C,QAAA,IAAI,cAAc,GAAG,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etryTransition, JobTransition
|
|
|
2
2
|
import EventEmitter from 'events';
|
|
3
3
|
import { inspect } from 'util';
|
|
4
4
|
import { JobTransitioner } from '../job/job-transitioner.js';
|
|
5
|
+
import 'node:fs';
|
|
6
|
+
import 'node:path';
|
|
7
|
+
import 'node:url';
|
|
5
8
|
import { RunnerPool } from '../shared-runner/runner-pool.js';
|
|
6
9
|
|
|
7
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor-manager.js","sources":["../../src/execution/executor-manager.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"executor-manager.js","sources":["../../src/execution/executor-manager.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAgBA;;AAEG;MACU,eAAe,CAAA;AAWhB,IAAA,OAAA;AACA,IAAA,aAAA;AAXF,IAAA,aAAa;AACb,IAAA,UAAU;AACV,IAAA,UAAU;AAElB;;;;AAIG;IACH,WAAA,CACU,OAAgB,EAChB,aAAsC,EAAA;QADtC,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,aAAa,GAAb,aAAa;AAErB,QAAA,IAAI,CAAC,aAAa,GAAG,EAAE;AACvB,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC;IACtD;AAEA;;;;AAIG;AACH,IAAA,qBAAqB,CAAC,WAAwB,EAAA;QAC5C,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE;YACzC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE;QAClD;QACA,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC;AACvD,QAAA,MAAM,KAAK,GAAG,WAAW,CAAC,WAAW,IAAI,EAAE;AAE3C,QAA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ist/index.cjs
CHANGED
|
@@ -6,12 +6,14 @@ var dispatcher = require('./execution/dispatcher.cjs');
|
|
|
6
6
|
var executorManager = require('./execution/executor-manager.cjs');
|
|
7
7
|
var queueManager = require('./execution/queue-manager.cjs');
|
|
8
8
|
var constants$1 = require('./job/constants.cjs');
|
|
9
|
+
var cronRegistry = require('./job/cron-registry.cjs');
|
|
9
10
|
var jobBuilder = require('./job/job-builder.cjs');
|
|
10
11
|
var jobTransitioner = require('./job/job-transitioner.cjs');
|
|
11
12
|
var grantQueueConfig = require('./queue/grant-queue-config.cjs');
|
|
12
13
|
var cleanupFinishedJob = require('./routines/cleanup-finished-job.cjs');
|
|
13
14
|
var releaseStaleJobs = require('./routines/release-stale-jobs.cjs');
|
|
14
15
|
var runner = require('./shared-runner/runner.cjs');
|
|
16
|
+
var manualLoader = require('./shared-runner/manual-loader.cjs');
|
|
15
17
|
var runnerPool = require('./shared-runner/runner-pool.cjs');
|
|
16
18
|
var _import = require('./utils/import.cjs');
|
|
17
19
|
var shutdown = require('./utils/shutdown.cjs');
|
|
@@ -26,6 +28,7 @@ exports.Dispatcher = dispatcher.Dispatcher;
|
|
|
26
28
|
exports.ExecutorManager = executorManager.ExecutorManager;
|
|
27
29
|
exports.QueueManager = queueManager.QueueManager;
|
|
28
30
|
exports.JOB_BUILDER_FALLBACK = constants$1.JOB_BUILDER_FALLBACK;
|
|
31
|
+
exports.ScheduledJobRegistry = cronRegistry.ScheduledJobRegistry;
|
|
29
32
|
exports.JobBuilder = jobBuilder.JobBuilder;
|
|
30
33
|
exports.JobTransitioner = jobTransitioner.JobTransitioner;
|
|
31
34
|
exports.differentQueueConfig = grantQueueConfig.differentQueueConfig;
|
|
@@ -33,6 +36,8 @@ exports.grantQueueConfig = grantQueueConfig.grantQueueConfig;
|
|
|
33
36
|
exports.cleanupFinishedJobs = cleanupFinishedJob.cleanupFinishedJobs;
|
|
34
37
|
exports.releaseStaleJobs = releaseStaleJobs.releaseStaleJobs;
|
|
35
38
|
exports.run = runner;
|
|
39
|
+
exports.MANUAL_SCRIPT_TAG = manualLoader.MANUAL_SCRIPT_TAG;
|
|
40
|
+
exports.findSidequestJobsScriptInParentDirs = manualLoader.findSidequestJobsScriptInParentDirs;
|
|
36
41
|
exports.RunnerPool = runnerPool.RunnerPool;
|
|
37
42
|
exports.importSidequest = _import.importSidequest;
|
|
38
43
|
exports.clearGracefulShutdown = shutdown.clearGracefulShutdown;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { Dispatcher } from './execution/dispatcher.js';
|
|
|
4
4
|
export { ExecutorManager } from './execution/executor-manager.js';
|
|
5
5
|
export { QueueManager } from './execution/queue-manager.js';
|
|
6
6
|
export { JOB_BUILDER_FALLBACK } from './job/constants.js';
|
|
7
|
+
export { ScheduledJobRegistry } from './job/cron-registry.js';
|
|
7
8
|
export { JobBuilder, JobBuilderDefaults, UniquenessInput } from './job/job-builder.js';
|
|
8
9
|
export { JobTransitioner } from './job/job-transitioner.js';
|
|
9
10
|
export { QueueDefaults, differentQueueConfig, grantQueueConfig } from './queue/grant-queue-config.js';
|
|
@@ -11,6 +12,7 @@ export { cleanupFinishedJobs } from './routines/cleanup-finished-job.js';
|
|
|
11
12
|
export { releaseStaleJobs } from './routines/release-stale-jobs.js';
|
|
12
13
|
import * as runner from './shared-runner/runner.js';
|
|
13
14
|
export { runner as run };
|
|
15
|
+
export { MANUAL_SCRIPT_TAG, findSidequestJobsScriptInParentDirs } from './shared-runner/manual-loader.js';
|
|
14
16
|
export { RunnerPool } from './shared-runner/runner-pool.js';
|
|
15
17
|
export { importSidequest } from './utils/import.js';
|
|
16
18
|
export { clearGracefulShutdown, gracefulShutdown } from './utils/shutdown.js';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { Dispatcher } from './execution/dispatcher.js';
|
|
|
4
4
|
export { ExecutorManager } from './execution/executor-manager.js';
|
|
5
5
|
export { QueueManager } from './execution/queue-manager.js';
|
|
6
6
|
export { JOB_BUILDER_FALLBACK } from './job/constants.js';
|
|
7
|
+
export { ScheduledJobRegistry } from './job/cron-registry.js';
|
|
7
8
|
export { JobBuilder } from './job/job-builder.js';
|
|
8
9
|
export { JobTransitioner } from './job/job-transitioner.js';
|
|
9
10
|
export { differentQueueConfig, grantQueueConfig } from './queue/grant-queue-config.js';
|
|
@@ -11,6 +12,7 @@ export { cleanupFinishedJobs } from './routines/cleanup-finished-job.js';
|
|
|
11
12
|
export { releaseStaleJobs } from './routines/release-stale-jobs.js';
|
|
12
13
|
import * as runner from './shared-runner/runner.js';
|
|
13
14
|
export { runner as run };
|
|
15
|
+
export { MANUAL_SCRIPT_TAG, findSidequestJobsScriptInParentDirs } from './shared-runner/manual-loader.js';
|
|
14
16
|
export { RunnerPool } from './shared-runner/runner-pool.js';
|
|
15
17
|
export { importSidequest } from './utils/import.js';
|
|
16
18
|
export { clearGracefulShutdown, gracefulShutdown } from './utils/shutdown.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@sidequest/core');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A registry for tracking and managing scheduled cron jobs.
|
|
7
|
+
* This allows centralized control over all scheduled tasks for proper cleanup.
|
|
8
|
+
*/
|
|
9
|
+
class ScheduledJobRegistry {
|
|
10
|
+
static scheduledTasks = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* Register a scheduled task in the registry.
|
|
13
|
+
* @param task - The scheduled task to register
|
|
14
|
+
* @returns A unique task ID for the registered task
|
|
15
|
+
*/
|
|
16
|
+
static register(task) {
|
|
17
|
+
this.scheduledTasks.set(task.id, task);
|
|
18
|
+
core.logger("CronRegistry").debug(`Registered scheduled task ${task.id}`);
|
|
19
|
+
return task.id;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Unregister and stop a specific scheduled task.
|
|
23
|
+
* @param taskId - The ID of the task to unregister
|
|
24
|
+
* @returns True if the task was found and stopped, false otherwise
|
|
25
|
+
*/
|
|
26
|
+
static async stop(taskId) {
|
|
27
|
+
const task = this.scheduledTasks.get(taskId);
|
|
28
|
+
if (task) {
|
|
29
|
+
try {
|
|
30
|
+
await task.stop();
|
|
31
|
+
core.logger("CronRegistry").debug(`Stopped scheduled task ${taskId}`);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
core.logger("CronRegistry").error(`Error stopping scheduled task ${taskId}:`, error);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
this.scheduledTasks.delete(taskId);
|
|
40
|
+
core.logger("CronRegistry").debug(`Unregistered scheduled task ${taskId}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Stop and unregister all scheduled tasks.
|
|
47
|
+
* This should be called during application shutdown to ensure proper cleanup.
|
|
48
|
+
*/
|
|
49
|
+
static async stopAll() {
|
|
50
|
+
const taskCount = this.scheduledTasks.size;
|
|
51
|
+
if (taskCount === 0) {
|
|
52
|
+
core.logger("CronRegistry").debug("No scheduled tasks to stop");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
core.logger("CronRegistry").info(`Stopping ${taskCount} scheduled task(s)...`);
|
|
56
|
+
for (const [taskId, task] of this.scheduledTasks) {
|
|
57
|
+
try {
|
|
58
|
+
await task.stop();
|
|
59
|
+
core.logger("CronRegistry").debug(`Stopped scheduled task ${taskId}`);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
core.logger("CronRegistry").error(`Error stopping scheduled task ${taskId}:`, error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
this.scheduledTasks.clear();
|
|
66
|
+
core.logger("CronRegistry").info("All scheduled tasks stopped and registry cleared");
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the number of registered tasks.
|
|
70
|
+
* @returns The count of registered tasks
|
|
71
|
+
*/
|
|
72
|
+
static getTaskCount() {
|
|
73
|
+
return this.scheduledTasks.size;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check if a task is registered.
|
|
77
|
+
* @param taskId - The ID of the task to check
|
|
78
|
+
* @returns True if the task is registered, false otherwise
|
|
79
|
+
*/
|
|
80
|
+
static hasTask(taskId) {
|
|
81
|
+
return this.scheduledTasks.has(taskId);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.ScheduledJobRegistry = ScheduledJobRegistry;
|
|
86
|
+
//# sourceMappingURL=cron-registry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cron-registry.cjs","sources":["../../src/job/cron-registry.ts"],"sourcesContent":[null],"names":["logger"],"mappings":";;;;AAGA;;;AAGG;MACU,oBAAoB,CAAA;AACvB,IAAA,OAAO,cAAc,GAAG,IAAI,GAAG,EAAyB;AAEhE;;;;AAIG;IACH,OAAO,QAAQ,CAAC,IAAmB,EAAA;QACjC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC;AACtC,QAAAA,WAAM,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,CAAA,0BAAA,EAA6B,IAAI,CAAC,EAAE,CAAA,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CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,CAAA,uBAAA,EAA0B,MAAM,CAAA,CAAE,CAAC;YAClE;YAAE,OAAO,KAAK,EAAE;AACd,gBAAAA,WAAM,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,CAAA,8BAAA,EAAiC,MAAM,CAAA,CAAA,CAAG,EAAE,KAAK,CAAC;YACjF;QACF;AAEA,QAAA,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE;QAC3BA,WAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,kDAAkD,CAAC;IACjF;AAEA;;;AAGG;AACH,IAAA,OAAO,YAAY,GAAA;AACjB,QAAA,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI;IACjC;AAEA;;;;AAIG;IACH,OAAO,OAAO,CAAC,MAAc,EAAA;QAC3B,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC;IACxC;;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ScheduledTask } from 'node-cron';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A registry for tracking and managing scheduled cron jobs.
|
|
5
|
+
* This allows centralized control over all scheduled tasks for proper cleanup.
|
|
6
|
+
*/
|
|
7
|
+
declare class ScheduledJobRegistry {
|
|
8
|
+
private static scheduledTasks;
|
|
9
|
+
/**
|
|
10
|
+
* Register a scheduled task in the registry.
|
|
11
|
+
* @param task - The scheduled task to register
|
|
12
|
+
* @returns A unique task ID for the registered task
|
|
13
|
+
*/
|
|
14
|
+
static register(task: ScheduledTask): string;
|
|
15
|
+
/**
|
|
16
|
+
* Unregister and stop a specific scheduled task.
|
|
17
|
+
* @param taskId - The ID of the task to unregister
|
|
18
|
+
* @returns True if the task was found and stopped, false otherwise
|
|
19
|
+
*/
|
|
20
|
+
static stop(taskId: string): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Stop and unregister all scheduled tasks.
|
|
23
|
+
* This should be called during application shutdown to ensure proper cleanup.
|
|
24
|
+
*/
|
|
25
|
+
static stopAll(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Get the number of registered tasks.
|
|
28
|
+
* @returns The count of registered tasks
|
|
29
|
+
*/
|
|
30
|
+
static getTaskCount(): number;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a task is registered.
|
|
33
|
+
* @param taskId - The ID of the task to check
|
|
34
|
+
* @returns True if the task is registered, false otherwise
|
|
35
|
+
*/
|
|
36
|
+
static hasTask(taskId: string): boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { ScheduledJobRegistry };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { logger } from '@sidequest/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A registry for tracking and managing scheduled cron jobs.
|
|
5
|
+
* This allows centralized control over all scheduled tasks for proper cleanup.
|
|
6
|
+
*/
|
|
7
|
+
class ScheduledJobRegistry {
|
|
8
|
+
static scheduledTasks = new Map();
|
|
9
|
+
/**
|
|
10
|
+
* Register a scheduled task in the registry.
|
|
11
|
+
* @param task - The scheduled task to register
|
|
12
|
+
* @returns A unique task ID for the registered task
|
|
13
|
+
*/
|
|
14
|
+
static register(task) {
|
|
15
|
+
this.scheduledTasks.set(task.id, task);
|
|
16
|
+
logger("CronRegistry").debug(`Registered scheduled task ${task.id}`);
|
|
17
|
+
return task.id;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Unregister and stop a specific scheduled task.
|
|
21
|
+
* @param taskId - The ID of the task to unregister
|
|
22
|
+
* @returns True if the task was found and stopped, false otherwise
|
|
23
|
+
*/
|
|
24
|
+
static async stop(taskId) {
|
|
25
|
+
const task = this.scheduledTasks.get(taskId);
|
|
26
|
+
if (task) {
|
|
27
|
+
try {
|
|
28
|
+
await task.stop();
|
|
29
|
+
logger("CronRegistry").debug(`Stopped scheduled task ${taskId}`);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
logger("CronRegistry").error(`Error stopping scheduled task ${taskId}:`, error);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
this.scheduledTasks.delete(taskId);
|
|
38
|
+
logger("CronRegistry").debug(`Unregistered scheduled task ${taskId}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Stop and unregister all scheduled tasks.
|
|
45
|
+
* This should be called during application shutdown to ensure proper cleanup.
|
|
46
|
+
*/
|
|
47
|
+
static async stopAll() {
|
|
48
|
+
const taskCount = this.scheduledTasks.size;
|
|
49
|
+
if (taskCount === 0) {
|
|
50
|
+
logger("CronRegistry").debug("No scheduled tasks to stop");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
logger("CronRegistry").info(`Stopping ${taskCount} scheduled task(s)...`);
|
|
54
|
+
for (const [taskId, task] of this.scheduledTasks) {
|
|
55
|
+
try {
|
|
56
|
+
await task.stop();
|
|
57
|
+
logger("CronRegistry").debug(`Stopped scheduled task ${taskId}`);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
logger("CronRegistry").error(`Error stopping scheduled task ${taskId}:`, error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
this.scheduledTasks.clear();
|
|
64
|
+
logger("CronRegistry").info("All scheduled tasks stopped and registry cleared");
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the number of registered tasks.
|
|
68
|
+
* @returns The count of registered tasks
|
|
69
|
+
*/
|
|
70
|
+
static getTaskCount() {
|
|
71
|
+
return this.scheduledTasks.size;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Check if a task is registered.
|
|
75
|
+
* @param taskId - The ID of the task to check
|
|
76
|
+
* @returns True if the task is registered, false otherwise
|
|
77
|
+
*/
|
|
78
|
+
static hasTask(taskId) {
|
|
79
|
+
return this.scheduledTasks.has(taskId);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { ScheduledJobRegistry };
|
|
84
|
+
//# sourceMappingURL=cron-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cron-registry.js","sources":["../../src/job/cron-registry.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;AAGG;MACU,oBAAoB,CAAA;AACvB,IAAA,OAAO,cAAc,GAAG,IAAI,GAAG,EAAyB;AAEhE;;;;AAIG;IACH,OAAO,QAAQ,CAAC,IAAmB,EAAA;QACjC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC;AACtC,QAAA,MAAM,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,CAAA,0BAAA,EAA6B,IAAI,CAAC,EAAE,CAAA,CAAE,CAAC;QACpE,OAAO,IAAI,CAAC,EAAE;IAChB;AAEA;;;;AAIG;AACH,IAAA,aAAa,IAAI,CAAC,MAAc,EAAA;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC;QAC5C,IAAI,IAAI,EAAE;AACR,YAAA,IAAI;AACF,gBAAA,MAAM,IAAI,CAAC,IAAI,EAAE;gBACjB,MAAM,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,CAAA,uBAAA,EAA0B,MAAM,CAAA,CAAE,CAAC;AAChE,gBAAA,OAAO,IAAI;YACb;YAAE,OAAO,KAAK,EAAE;AACd,gBAAA,MAAM,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,CAAA,8BAAA,EAAiC,MAAM,CAAA,CAAA,CAAG,EAAE,KAAK,CAAC;AAC/E,gBAAA,OAAO,KAAK;YACd;oBAAU;AACR,gBAAA,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC;gBAClC,MAAM,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,CAAA,4BAAA,EAA+B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|
var node_util = require('node:util');
|
|
6
|
+
var manualLoader = require('../shared-runner/manual-loader.cjs');
|
|
7
|
+
require('piscina');
|
|
8
|
+
require('../constants.cjs');
|
|
6
9
|
var constants = require('./constants.cjs');
|
|
10
|
+
var cronRegistry = require('./cron-registry.cjs');
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Builder for creating and enqueuing jobs with custom configuration.
|
|
@@ -13,6 +17,7 @@ class JobBuilder {
|
|
|
13
17
|
backend;
|
|
14
18
|
JobClass;
|
|
15
19
|
defaults;
|
|
20
|
+
manualJobResolution;
|
|
16
21
|
constructorArgs;
|
|
17
22
|
queueName;
|
|
18
23
|
jobTimeout;
|
|
@@ -23,10 +28,11 @@ class JobBuilder {
|
|
|
23
28
|
* Creates a new JobBuilder for the given job class.
|
|
24
29
|
* @param JobClass The job class constructor.
|
|
25
30
|
*/
|
|
26
|
-
constructor(backend, JobClass, defaults) {
|
|
31
|
+
constructor(backend, JobClass, defaults, manualJobResolution = false) {
|
|
27
32
|
this.backend = backend;
|
|
28
33
|
this.JobClass = JobClass;
|
|
29
34
|
this.defaults = defaults;
|
|
35
|
+
this.manualJobResolution = manualJobResolution;
|
|
30
36
|
this.queue(this.defaults?.queue ?? constants.JOB_BUILDER_FALLBACK.queue);
|
|
31
37
|
this.maxAttempts(this.defaults?.maxAttempts ?? constants.JOB_BUILDER_FALLBACK.maxAttempts);
|
|
32
38
|
this.availableAt(this.defaults?.availableAt ?? constants.JOB_BUILDER_FALLBACK.availableAt);
|
|
@@ -118,7 +124,16 @@ class JobBuilder {
|
|
|
118
124
|
}
|
|
119
125
|
async build(...args) {
|
|
120
126
|
const job = new this.JobClass(...this.constructorArgs);
|
|
121
|
-
|
|
127
|
+
if (!this.manualJobResolution) {
|
|
128
|
+
// This resolves the job script path using exception handling.
|
|
129
|
+
await job.ready();
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// If manual resolution is enabled, we skip automatic script resolution.
|
|
133
|
+
// The user is responsible for ensuring the job class is properly exported
|
|
134
|
+
// in the `sidequest.jobs.js` file.
|
|
135
|
+
Object.assign(job, { script: manualLoader.MANUAL_SCRIPT_TAG });
|
|
136
|
+
}
|
|
122
137
|
if (!job.script) {
|
|
123
138
|
throw new Error(`Error on starting job ${job.className} could not detect source file.`);
|
|
124
139
|
}
|
|
@@ -162,10 +177,11 @@ class JobBuilder {
|
|
|
162
177
|
* @remarks
|
|
163
178
|
* - The schedule is **not persisted** to any database. It will be lost if the process restarts and must be re-registered at startup.
|
|
164
179
|
* - You must call this method during application initialization to ensure the job is scheduled correctly.
|
|
165
|
-
* - Uses node-cron
|
|
180
|
+
* - Uses node-cron's `noOverlap: true` option to prevent concurrent executions.
|
|
181
|
+
* - The scheduled task is registered with the CronRegistry for proper cleanup during shutdown.
|
|
166
182
|
*
|
|
167
183
|
* @param cronExpression - A valid cron expression (node-cron compatible) that defines when the job should be enqueued.
|
|
168
|
-
* @param args - Arguments to be passed to the job
|
|
184
|
+
* @param args - Arguments to be passed to the job's `run` method on each scheduled execution.
|
|
169
185
|
*
|
|
170
186
|
* @returns The underlying `ScheduledTask` instance created by node-cron.
|
|
171
187
|
*
|
|
@@ -184,11 +200,14 @@ class JobBuilder {
|
|
|
184
200
|
Object.freeze(jobData);
|
|
185
201
|
core.logger("JobBuilder").debug(`Scheduling job ${jobData.class} with cron: "${cronExpression}", args: ${node_util.inspect(args)}, ` +
|
|
186
202
|
`constructor args: ${node_util.inspect(this.constructorArgs)}`);
|
|
187
|
-
|
|
203
|
+
const scheduledTask = nodeCron.schedule(cronExpression, async () => {
|
|
188
204
|
const newJobData = Object.assign({}, jobData);
|
|
189
205
|
core.logger("JobBuilder").debug(`Cron triggered for job ${newJobData.class} at ${newJobData.available_at.toISOString()} with args: ${node_util.inspect(args)}`);
|
|
190
206
|
return this.backend.createNewJob(jobData);
|
|
191
207
|
}, { noOverlap: true });
|
|
208
|
+
// Register the scheduled task with the ScheduledJobRegistry for proper later cleanup
|
|
209
|
+
cronRegistry.ScheduledJobRegistry.register(scheduledTask);
|
|
210
|
+
return scheduledTask;
|
|
192
211
|
}
|
|
193
212
|
}
|
|
194
213
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-builder.cjs","sources":["../../src/job/job-builder.ts"],"sourcesContent":[null],"names":["JOB_BUILDER_FALLBACK","UniquenessFactory","logger","inspect"],"mappings":"
|
|
1
|
+
{"version":3,"file":"job-builder.cjs","sources":["../../src/job/job-builder.ts"],"sourcesContent":[null],"names":["JOB_BUILDER_FALLBACK","MANUAL_SCRIPT_TAG","UniquenessFactory","logger","inspect","ScheduledJobRegistry"],"mappings":";;;;;;;;;;;AA6DA;;;AAGG;MACU,UAAU,CAAA;AAaT,IAAA,OAAA;AACA,IAAA,QAAA;AACA,IAAA,QAAA;AACA,IAAA,mBAAA;AAfF,IAAA,eAAe;AACf,IAAA,SAAS;AACT,IAAA,UAAU;AACV,IAAA,gBAAgB;AAChB,IAAA,cAAc;AACd,IAAA,cAAc;AAExB;;;AAGG;AACH,IAAA,WAAA,CACY,OAAgB,EAChB,QAAW,EACX,QAA6B,EAC7B,sBAAsB,KAAK,EAAA;QAH3B,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,QAAQ,GAAR,QAAQ;QACR,IAAA,CAAA,QAAQ,GAAR,QAAQ;QACR,IAAA,CAAA,mBAAmB,GAAnB,mBAAmB;AAE7B,QAAA,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAIA,8BAAoB,CAAC,KAAM,CAAC;AAC/D,QAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,IAAIA,8BAAoB,CAAC,WAAY,CAAC;AACjF,QAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,IAAIA,8BAAoB,CAAC,WAAY,CAAC;AACjF,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EA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AAA,EAAYC,iBAAO,CAAC,IAAI,CAAC,CAAA,EAAA,CAAI;YACxF,CAAA,kBAAA,EAAqBA,iBAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA,CAAE,CACvD;QAED,MAAM,aAAa,GAAG,QAAQ,CAAC,QAAQ,CACrC,cAAc,EACd,YAAW;YACT,MAAM,UAAU,GAAe,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC;YACzDD,WAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CACxB,CAAA,uBAAA,EAA0B,UAAU,CAAC,KAAK,CAAA,IAAA,EAAO,UAAU,CAAC,YAAa,CAAC,WAAW,EAAE,CAAA,YAAA,EAAeC,iBAAO,CAAC,IAAI,CAAC,CAAA,CAAE,CACtH;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC;AAC3C,QAAA,CAAC,EACD,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB;;AAGD,QAAAC,iCAAoB,CAAC,QAAQ,CAAC,aAAa,CAAC;AAE5C,QAAA,OAAO,aAAa;IACtB;AACD;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Backend } from '@sidequest/backend';
|
|
2
|
-
import { TimePeriod, JobClassType, JobData } from '@sidequest/core';
|
|
1
|
+
import { Backend, NewJobData } from '@sidequest/backend';
|
|
2
|
+
import { TimePeriod, JobClassType, UniquenessConfig, JobData } from '@sidequest/core';
|
|
3
3
|
import { ScheduledTask } from 'node-cron';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -48,20 +48,21 @@ interface JobBuilderDefaults {
|
|
|
48
48
|
* @template T The job class type.
|
|
49
49
|
*/
|
|
50
50
|
declare class JobBuilder<T extends JobClassType> {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
protected backend: Backend;
|
|
52
|
+
protected JobClass: T;
|
|
53
|
+
protected defaults?: JobBuilderDefaults | undefined;
|
|
54
|
+
protected manualJobResolution: boolean;
|
|
55
|
+
protected constructorArgs?: ConstructorParameters<T>;
|
|
56
|
+
protected queueName?: string;
|
|
57
|
+
protected jobTimeout?: number;
|
|
58
|
+
protected uniquenessConfig?: UniquenessConfig;
|
|
59
|
+
protected jobMaxAttempts?: number;
|
|
60
|
+
protected jobAvailableAt?: Date;
|
|
60
61
|
/**
|
|
61
62
|
* Creates a new JobBuilder for the given job class.
|
|
62
63
|
* @param JobClass The job class constructor.
|
|
63
64
|
*/
|
|
64
|
-
constructor(backend: Backend, JobClass: T, defaults?: JobBuilderDefaults | undefined);
|
|
65
|
+
constructor(backend: Backend, JobClass: T, defaults?: JobBuilderDefaults | undefined, manualJobResolution?: boolean);
|
|
65
66
|
/**
|
|
66
67
|
* Sets the constructor arguments for the job.
|
|
67
68
|
* @param args The constructor arguments.
|
|
@@ -103,7 +104,7 @@ declare class JobBuilder<T extends JobClassType> {
|
|
|
103
104
|
* @returns This builder instance.
|
|
104
105
|
*/
|
|
105
106
|
availableAt(value: Date): this;
|
|
106
|
-
|
|
107
|
+
protected build(...args: Parameters<InstanceType<T>["run"]>): Promise<NewJobData>;
|
|
107
108
|
/**
|
|
108
109
|
* Enqueues the job with the specified arguments.
|
|
109
110
|
* @param args Arguments to pass to the job's run method.
|
|
@@ -119,10 +120,11 @@ declare class JobBuilder<T extends JobClassType> {
|
|
|
119
120
|
* @remarks
|
|
120
121
|
* - The schedule is **not persisted** to any database. It will be lost if the process restarts and must be re-registered at startup.
|
|
121
122
|
* - You must call this method during application initialization to ensure the job is scheduled correctly.
|
|
122
|
-
* - Uses node-cron
|
|
123
|
+
* - Uses node-cron's `noOverlap: true` option to prevent concurrent executions.
|
|
124
|
+
* - The scheduled task is registered with the CronRegistry for proper cleanup during shutdown.
|
|
123
125
|
*
|
|
124
126
|
* @param cronExpression - A valid cron expression (node-cron compatible) that defines when the job should be enqueued.
|
|
125
|
-
* @param args - Arguments to be passed to the job
|
|
127
|
+
* @param args - Arguments to be passed to the job's `run` method on each scheduled execution.
|
|
126
128
|
*
|
|
127
129
|
* @returns The underlying `ScheduledTask` instance created by node-cron.
|
|
128
130
|
*
|
package/dist/job/job-builder.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { UniquenessFactory, logger } from '@sidequest/core';
|
|
2
2
|
import nodeCron from 'node-cron';
|
|
3
3
|
import { inspect } from 'node:util';
|
|
4
|
+
import { MANUAL_SCRIPT_TAG } from '../shared-runner/manual-loader.js';
|
|
5
|
+
import 'piscina';
|
|
6
|
+
import '../constants.js';
|
|
4
7
|
import { JOB_BUILDER_FALLBACK } from './constants.js';
|
|
8
|
+
import { ScheduledJobRegistry } from './cron-registry.js';
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Builder for creating and enqueuing jobs with custom configuration.
|
|
@@ -11,6 +15,7 @@ class JobBuilder {
|
|
|
11
15
|
backend;
|
|
12
16
|
JobClass;
|
|
13
17
|
defaults;
|
|
18
|
+
manualJobResolution;
|
|
14
19
|
constructorArgs;
|
|
15
20
|
queueName;
|
|
16
21
|
jobTimeout;
|
|
@@ -21,10 +26,11 @@ class JobBuilder {
|
|
|
21
26
|
* Creates a new JobBuilder for the given job class.
|
|
22
27
|
* @param JobClass The job class constructor.
|
|
23
28
|
*/
|
|
24
|
-
constructor(backend, JobClass, defaults) {
|
|
29
|
+
constructor(backend, JobClass, defaults, manualJobResolution = false) {
|
|
25
30
|
this.backend = backend;
|
|
26
31
|
this.JobClass = JobClass;
|
|
27
32
|
this.defaults = defaults;
|
|
33
|
+
this.manualJobResolution = manualJobResolution;
|
|
28
34
|
this.queue(this.defaults?.queue ?? JOB_BUILDER_FALLBACK.queue);
|
|
29
35
|
this.maxAttempts(this.defaults?.maxAttempts ?? JOB_BUILDER_FALLBACK.maxAttempts);
|
|
30
36
|
this.availableAt(this.defaults?.availableAt ?? JOB_BUILDER_FALLBACK.availableAt);
|
|
@@ -116,7 +122,16 @@ class JobBuilder {
|
|
|
116
122
|
}
|
|
117
123
|
async build(...args) {
|
|
118
124
|
const job = new this.JobClass(...this.constructorArgs);
|
|
119
|
-
|
|
125
|
+
if (!this.manualJobResolution) {
|
|
126
|
+
// This resolves the job script path using exception handling.
|
|
127
|
+
await job.ready();
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// If manual resolution is enabled, we skip automatic script resolution.
|
|
131
|
+
// The user is responsible for ensuring the job class is properly exported
|
|
132
|
+
// in the `sidequest.jobs.js` file.
|
|
133
|
+
Object.assign(job, { script: MANUAL_SCRIPT_TAG });
|
|
134
|
+
}
|
|
120
135
|
if (!job.script) {
|
|
121
136
|
throw new Error(`Error on starting job ${job.className} could not detect source file.`);
|
|
122
137
|
}
|
|
@@ -160,10 +175,11 @@ class JobBuilder {
|
|
|
160
175
|
* @remarks
|
|
161
176
|
* - The schedule is **not persisted** to any database. It will be lost if the process restarts and must be re-registered at startup.
|
|
162
177
|
* - You must call this method during application initialization to ensure the job is scheduled correctly.
|
|
163
|
-
* - Uses node-cron
|
|
178
|
+
* - Uses node-cron's `noOverlap: true` option to prevent concurrent executions.
|
|
179
|
+
* - The scheduled task is registered with the CronRegistry for proper cleanup during shutdown.
|
|
164
180
|
*
|
|
165
181
|
* @param cronExpression - A valid cron expression (node-cron compatible) that defines when the job should be enqueued.
|
|
166
|
-
* @param args - Arguments to be passed to the job
|
|
182
|
+
* @param args - Arguments to be passed to the job's `run` method on each scheduled execution.
|
|
167
183
|
*
|
|
168
184
|
* @returns The underlying `ScheduledTask` instance created by node-cron.
|
|
169
185
|
*
|
|
@@ -182,11 +198,14 @@ class JobBuilder {
|
|
|
182
198
|
Object.freeze(jobData);
|
|
183
199
|
logger("JobBuilder").debug(`Scheduling job ${jobData.class} with cron: "${cronExpression}", args: ${inspect(args)}, ` +
|
|
184
200
|
`constructor args: ${inspect(this.constructorArgs)}`);
|
|
185
|
-
|
|
201
|
+
const scheduledTask = nodeCron.schedule(cronExpression, async () => {
|
|
186
202
|
const newJobData = Object.assign({}, jobData);
|
|
187
203
|
logger("JobBuilder").debug(`Cron triggered for job ${newJobData.class} at ${newJobData.available_at.toISOString()} with args: ${inspect(args)}`);
|
|
188
204
|
return this.backend.createNewJob(jobData);
|
|
189
205
|
}, { noOverlap: true });
|
|
206
|
+
// Register the scheduled task with the ScheduledJobRegistry for proper later cleanup
|
|
207
|
+
ScheduledJobRegistry.register(scheduledTask);
|
|
208
|
+
return scheduledTask;
|
|
190
209
|
}
|
|
191
210
|
}
|
|
192
211
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-builder.js","sources":["../../src/job/job-builder.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"job-builder.js","sources":["../../src/job/job-builder.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AA6DA;;;AAGG;MACU,UAAU,CAAA;AAaT,IAAA,OAAA;AACA,IAAA,QAAA;AACA,IAAA,QAAA;AACA,IAAA,mBAAA;AAfF,IAAA,eAAe;AACf,IAAA,SAAS;AACT,IAAA,UAAU;AACV,IAAA,gBAAgB;AAChB,IAAA,cAAc;AACd,IAAA,cAAc;AAExB;;;AAGG;AACH,IAAA,WAAA,CACY,OAAgB,EAChB,QAAW,EACX,QAA6B,EAC7B,sBAAsB,KAAK,EAAA;QAH3B,IAAA,CAAA,OAAO,GAAP,OAAO;QACP,IAAA,CAAA,QAAQ,GAAR,QAAQ;QACR,IAAA,CAAA,QAAQ,GAAR,QAAQ;QACR,IAAA,CAAA,mBAAmB,GAAnB,mBAAmB;AAE7B,QAAA,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI,oBAAoB,CAAC,KAAM,CAAC;AAC/D,QAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,IAAI,oBAAoB,CAAC,WAAY,CAAC;AACjF,QAAA,I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AC,OAAO,CAAC;AAEtB,QAAA,MAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CACxB,CAAA,eAAA,EAAkB,OAAO,CAAC,KAAK,gBAAgB,cAAc,CAAA,SAAA,EAAY,OAAO,CAAC,IAAI,CAAC,CAAA,EAAA,CAAI;YACxF,CAAA,kBAAA,EAAqB,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA,CAAE,CACvD;QAED,MAAM,aAAa,GAAG,QAAQ,CAAC,QAAQ,CACrC,cAAc,EACd,YAAW;YACT,MAAM,UAAU,GAAe,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC;YACzD,MAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CACxB,CAAA,uBAAA,EAA0B,UAAU,CAAC,KAAK,CAAA,IAAA,EAAO,UAAU,CAAC,YAAa,CAAC,WAAW,EAAE,CAAA,YAAA,EAAe,OAAO,CAAC,IAAI,CAAC,CAAA,CAAE,CACtH;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC;AAC3C,QAAA,CAAC,EACD,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB;;AAGD,QAAA,oBAAoB,CAAC,QAAQ,CAAC,aAAa,CAAC;AAE5C,QAAA,OAAO,aAAa;IACtB;AACD;;;;"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_fs = require('node:fs');
|
|
4
|
+
var node_path = require('node:path');
|
|
5
|
+
var node_url = require('node:url');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Tag used to indicate that a job script should be resolved manually
|
|
9
|
+
* by searching the filesystem rather than importing directly.
|
|
10
|
+
*/
|
|
11
|
+
const MANUAL_SCRIPT_TAG = "sidequest.jobs.js";
|
|
12
|
+
/**
|
|
13
|
+
* Finds a file by searching in the current directory and walking up through parent directories.
|
|
14
|
+
*
|
|
15
|
+
* @param fileName - The name of the file to search for. Defaults to "sidequest.jobs.js"
|
|
16
|
+
* @param startDir - The directory to start searching from. Defaults to process.cwd()
|
|
17
|
+
* @returns The file URL path to the found file
|
|
18
|
+
* @throws {Error} If the file is not found in any directory up to the root
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Find sidequest.jobs.js starting from current directory
|
|
23
|
+
* const jobsFile = findFileInParentDirs();
|
|
24
|
+
*
|
|
25
|
+
* // Find a specific file starting from current directory
|
|
26
|
+
* const configFile = findFileInParentDirs("config.json");
|
|
27
|
+
*
|
|
28
|
+
* // Find a file starting from a specific directory
|
|
29
|
+
* const packageFile = findFileInParentDirs("package.json", "/some/project/dir");
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function findSidequestJobsScriptInParentDirs(fileName = "sidequest.jobs.js", startDir = process.cwd()) {
|
|
33
|
+
if (!fileName.trim()) {
|
|
34
|
+
throw new Error("fileName must be a non-empty string");
|
|
35
|
+
}
|
|
36
|
+
let currentDir = node_path.resolve(startDir);
|
|
37
|
+
const rootDir = node_path.resolve("/");
|
|
38
|
+
// Keep searching until we reach the root directory
|
|
39
|
+
while (currentDir !== rootDir) {
|
|
40
|
+
const filePath = node_path.join(currentDir, fileName);
|
|
41
|
+
if (node_fs.existsSync(filePath)) {
|
|
42
|
+
return node_url.pathToFileURL(filePath).href;
|
|
43
|
+
}
|
|
44
|
+
// Move to parent directory
|
|
45
|
+
const parentDir = node_path.dirname(currentDir);
|
|
46
|
+
// Safety check to prevent infinite loops
|
|
47
|
+
if (parentDir === currentDir) {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
currentDir = parentDir;
|
|
51
|
+
}
|
|
52
|
+
// Check the root directory as well
|
|
53
|
+
const rootFilePath = node_path.join(rootDir, fileName);
|
|
54
|
+
if (node_fs.existsSync(rootFilePath)) {
|
|
55
|
+
return node_url.pathToFileURL(rootFilePath).href;
|
|
56
|
+
}
|
|
57
|
+
throw new Error(`File "${fileName}" not found in "${startDir}" or any parent directory`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.MANUAL_SCRIPT_TAG = MANUAL_SCRIPT_TAG;
|
|
61
|
+
exports.findSidequestJobsScriptInParentDirs = findSidequestJobsScriptInParentDirs;
|
|
62
|
+
//# sourceMappingURL=manual-loader.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual-loader.cjs","sources":["../../src/shared-runner/manual-loader.ts"],"sourcesContent":[null],"names":["resolve","join","existsSync","pathToFileURL","dirname"],"mappings":";;;;;;AAIA;;;AAGG;AACI,MAAM,iBAAiB,GAAG;AAEjC;;;;;;;;;;;;;;;;;;;AAmBG;AACG,SAAU,mCAAmC,CAAC,QAAQ,GAAG,mBAAmB,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,EAAA;AAC1G,IAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE;AACpB,QAAA,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC;IACxD;AAEA,IAAA,IAAI,UAAU,GAAGA,iBAAO,CAAC,QAAQ,CAAC;AAClC,IAAA,MAAM,OAAO,GAAGA,iBAAO,CAAC,GAAG,CAAC;;AAG5B,IAAA,OAAO,UAAU,KAAK,OAAO,EAAE;QAC7B,MAAM,QAAQ,GAAGC,cAAI,CAAC,UAAU,EAAE,QAAQ,CAAC;AAE3C,QAAA,IAAIC,kBAAU,CAAC,QAAQ,CAAC,EAAE;AACxB,YAAA,OAAOC,sBAAa,CAAC,QAAQ,CAAC,CAAC,IAAI;QACrC;;AAGA,QAAA,MAAM,SAAS,GAAGC,iBAAO,CAAC,UAAU,CAAC;;AAGrC,QAAA,IAAI,SAAS,KAAK,UAAU,EAAE;YAC5B;QACF;QAEA,UAAU,GAAG,SAAS;IACxB;;IAGA,MAAM,YAAY,GAAGH,cAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;AAC5C,IAAA,IAAIC,kBAAU,CAAC,YAAY,CAAC,EAAE;AAC5B,QAAA,OAAOC,sBAAa,CAAC,YAAY,CAAC,CAAC,IAAI;IACzC;IAEA,MAAM,IAAI,KAAK,CAAC,CAAA,MAAA,EAAS,QAAQ,CAAA,gBAAA,EAAmB,QAAQ,CAAA,yBAAA,CAA2B,CAAC;AAC1F;;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tag used to indicate that a job script should be resolved manually
|
|
3
|
+
* by searching the filesystem rather than importing directly.
|
|
4
|
+
*/
|
|
5
|
+
declare const MANUAL_SCRIPT_TAG = "sidequest.jobs.js";
|
|
6
|
+
/**
|
|
7
|
+
* Finds a file by searching in the current directory and walking up through parent directories.
|
|
8
|
+
*
|
|
9
|
+
* @param fileName - The name of the file to search for. Defaults to "sidequest.jobs.js"
|
|
10
|
+
* @param startDir - The directory to start searching from. Defaults to process.cwd()
|
|
11
|
+
* @returns The file URL path to the found file
|
|
12
|
+
* @throws {Error} If the file is not found in any directory up to the root
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Find sidequest.jobs.js starting from current directory
|
|
17
|
+
* const jobsFile = findFileInParentDirs();
|
|
18
|
+
*
|
|
19
|
+
* // Find a specific file starting from current directory
|
|
20
|
+
* const configFile = findFileInParentDirs("config.json");
|
|
21
|
+
*
|
|
22
|
+
* // Find a file starting from a specific directory
|
|
23
|
+
* const packageFile = findFileInParentDirs("package.json", "/some/project/dir");
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare function findSidequestJobsScriptInParentDirs(fileName?: string, startDir?: string): string;
|
|
27
|
+
|
|
28
|
+
export { MANUAL_SCRIPT_TAG, findSidequestJobsScriptInParentDirs };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { resolve, join, dirname } from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tag used to indicate that a job script should be resolved manually
|
|
7
|
+
* by searching the filesystem rather than importing directly.
|
|
8
|
+
*/
|
|
9
|
+
const MANUAL_SCRIPT_TAG = "sidequest.jobs.js";
|
|
10
|
+
/**
|
|
11
|
+
* Finds a file by searching in the current directory and walking up through parent directories.
|
|
12
|
+
*
|
|
13
|
+
* @param fileName - The name of the file to search for. Defaults to "sidequest.jobs.js"
|
|
14
|
+
* @param startDir - The directory to start searching from. Defaults to process.cwd()
|
|
15
|
+
* @returns The file URL path to the found file
|
|
16
|
+
* @throws {Error} If the file is not found in any directory up to the root
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Find sidequest.jobs.js starting from current directory
|
|
21
|
+
* const jobsFile = findFileInParentDirs();
|
|
22
|
+
*
|
|
23
|
+
* // Find a specific file starting from current directory
|
|
24
|
+
* const configFile = findFileInParentDirs("config.json");
|
|
25
|
+
*
|
|
26
|
+
* // Find a file starting from a specific directory
|
|
27
|
+
* const packageFile = findFileInParentDirs("package.json", "/some/project/dir");
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function findSidequestJobsScriptInParentDirs(fileName = "sidequest.jobs.js", startDir = process.cwd()) {
|
|
31
|
+
if (!fileName.trim()) {
|
|
32
|
+
throw new Error("fileName must be a non-empty string");
|
|
33
|
+
}
|
|
34
|
+
let currentDir = resolve(startDir);
|
|
35
|
+
const rootDir = resolve("/");
|
|
36
|
+
// Keep searching until we reach the root directory
|
|
37
|
+
while (currentDir !== rootDir) {
|
|
38
|
+
const filePath = join(currentDir, fileName);
|
|
39
|
+
if (existsSync(filePath)) {
|
|
40
|
+
return pathToFileURL(filePath).href;
|
|
41
|
+
}
|
|
42
|
+
// Move to parent directory
|
|
43
|
+
const parentDir = dirname(currentDir);
|
|
44
|
+
// Safety check to prevent infinite loops
|
|
45
|
+
if (parentDir === currentDir) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
currentDir = parentDir;
|
|
49
|
+
}
|
|
50
|
+
// Check the root directory as well
|
|
51
|
+
const rootFilePath = join(rootDir, fileName);
|
|
52
|
+
if (existsSync(rootFilePath)) {
|
|
53
|
+
return pathToFileURL(rootFilePath).href;
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`File "${fileName}" not found in "${startDir}" or any parent directory`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { MANUAL_SCRIPT_TAG, findSidequestJobsScriptInParentDirs };
|
|
59
|
+
//# sourceMappingURL=manual-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual-loader.js","sources":["../../src/shared-runner/manual-loader.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;AAGG;AACI,MAAM,iBAAiB,GAAG;AAEjC;;;;;;;;;;;;;;;;;;;AAmBG;AACG,SAAU,mCAAmC,CAAC,QAAQ,GAAG,mBAAmB,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,EAAA;AAC1G,IAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE;AACpB,QAAA,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC;IACxD;AAEA,IAAA,IAAI,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC;AAClC,IAAA,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;;AAG5B,IAAA,OAAO,UAAU,KAAK,OAAO,EAAE;QAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC;AAE3C,QAAA,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE;AACxB,YAAA,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI;QACrC;;AAGA,QAAA,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC;;AAGrC,QAAA,IAAI,SAAS,KAAK,UAAU,EAAE;YAC5B;QACF;QAEA,UAAU,GAAG,SAAS;IACxB;;IAGA,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;AAC5C,IAAA,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE;AAC5B,QAAA,OAAO,aAAa,CAAC,YAAY,CAAC,CAAC,IAAI;IACzC;IAEA,MAAM,IAAI,KAAK,CAAC,CAAA,MAAA,EAAS,QAAQ,CAAA,gBAAA,EAAmB,QAAQ,CAAA,yBAAA,CAA2B,CAAC;AAC1F;;;;"}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var core = require('@sidequest/core');
|
|
6
6
|
var _import = require('../utils/import.cjs');
|
|
7
|
+
var manualLoader = require('./manual-loader.cjs');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Runs a job by dynamically importing its script and executing the specified class.
|
|
@@ -16,8 +17,25 @@ async function run({ jobData, config }) {
|
|
|
16
17
|
let script = {};
|
|
17
18
|
try {
|
|
18
19
|
core.logger("Runner").debug(`Importing job script "${jobData.script}"`);
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
let scriptUrl;
|
|
21
|
+
if (jobData.script === manualLoader.MANUAL_SCRIPT_TAG) {
|
|
22
|
+
core.logger("Runner").debug("Manual job resolution is enabled; importing 'sidequest.jobs.js' job script.");
|
|
23
|
+
try {
|
|
24
|
+
// When manual job resolution is enabled, import from the sidequest.jobs.js script
|
|
25
|
+
scriptUrl = manualLoader.findSidequestJobsScriptInParentDirs();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
const errorMessage = `Failed to locate 'sidequest.jobs.js' for manual job resolution: ${error instanceof Error ? error.message : String(error)}`;
|
|
29
|
+
core.logger("Runner").error(errorMessage);
|
|
30
|
+
const errorData = core.toErrorData(error);
|
|
31
|
+
return { __is_job_transition__: true, type: "failed", error: errorData };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
core.logger("Runner").debug("Manual job resolution is disabled; importing specified job script.");
|
|
36
|
+
// Convert relative path to absolute file URL for dynamic import
|
|
37
|
+
scriptUrl = core.resolveScriptPath(jobData.script);
|
|
38
|
+
}
|
|
21
39
|
script = (await import(scriptUrl));
|
|
22
40
|
core.logger("Runner").debug(`Successfully imported job script "${jobData.script}"`);
|
|
23
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.cjs","sources":["../../src/shared-runner/runner.ts"],"sourcesContent":[null],"names":["logger","
|
|
1
|
+
{"version":3,"file":"runner.cjs","sources":["../../src/shared-runner/runner.ts"],"sourcesContent":[null],"names":["logger","MANUAL_SCRIPT_TAG","findSidequestJobsScriptInParentDirs","toErrorData","resolveScriptPath","importSidequest"],"mappings":";;;;;;;;AAKA;;;;;AAKG;AACY,eAAe,GAAG,CAAC,EAAE,OAAO,EAAE,MAAM,EAA8C,EAAA;AAC/F,IAAA,MAAM,qBAAqB,CAAC,MAAM,CAAC;IAEnC,IAAI,MAAM,GAAiC,EAAE;AAC7C,IAAA,IAAI;AACF,QAAAA,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,sBAAA,EAAyB,OAAO,CAAC,MAAM,CAAA,CAAA,CAAG,CAAC;AAElE,QAAA,IAAI,SAAS;AACb,QAAA,IAAI,OAAO,CAAC,MAAM,KAAKC,8BAAiB,EAAE;YACxCD,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,6EAA6E,CAAC;AACrG,YAAA,IAAI;;gBAEF,SAAS,GAAGE,gDAAmC,EAAE;YACnD;YAAE,OAAO,KAAK,EAAE;gBACd,MAAM,YAAY,GAAG,CAAA,gEAAA,EAAmE,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE;gBAChJF,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC;AACpC,gBAAA,MAAM,SAAS,GAAGG,gBAAW,CAAC,KAAc,CAAC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AAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE;IAC1E;IAEA,MAAM,GAAG,GAAQ,IAAI,QAAQ,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC;AAC1D,IAAA,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC;AAE1B,IAAAH,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAA,qBAAA,EAAwB,OAAO,CAAC,KAAK,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC;IACzF,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;AACrC;AAEA;;;;;;;;;;AAUG;AACI,eAAe,qBAAqB,CAAC,MAAoB,EAAA;AAC9D,IAAA,IAAI;QACFA,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,4CAA4C,CAAC;AACpE,QAAA,MAAM,EAAE,SAAS,EAAE,GAAG,MAAMK,uBAAe,EAAE;AAC7C,QAAA,MAAM,SAAS,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;QAC7DL,WAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,wCAAwC,CAAC;AAChE,QAAA,OAAO,IAAI;IACb;IAAE,OAAO,KAAK,EAAE;QACdA,WAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CACnB,CAAA,mCAAA,EAAsC,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA,oBAAA,CAAsB,CACnH;AACD,QAAA,OAAO,KAAK;IACd;AACF;;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { logger,
|
|
1
|
+
import { logger, toErrorData, resolveScriptPath } from '@sidequest/core';
|
|
2
2
|
import { importSidequest } from '../utils/import.js';
|
|
3
|
+
import { MANUAL_SCRIPT_TAG, findSidequestJobsScriptInParentDirs } from './manual-loader.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Runs a job by dynamically importing its script and executing the specified class.
|
|
@@ -12,8 +13,25 @@ async function run({ jobData, config }) {
|
|
|
12
13
|
let script = {};
|
|
13
14
|
try {
|
|
14
15
|
logger("Runner").debug(`Importing job script "${jobData.script}"`);
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
let scriptUrl;
|
|
17
|
+
if (jobData.script === MANUAL_SCRIPT_TAG) {
|
|
18
|
+
logger("Runner").debug("Manual job resolution is enabled; importing 'sidequest.jobs.js' job script.");
|
|
19
|
+
try {
|
|
20
|
+
// When manual job resolution is enabled, import from the sidequest.jobs.js script
|
|
21
|
+
scriptUrl = findSidequestJobsScriptInParentDirs();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
const errorMessage = `Failed to locate 'sidequest.jobs.js' for manual job resolution: ${error instanceof Error ? error.message : String(error)}`;
|
|
25
|
+
logger("Runner").error(errorMessage);
|
|
26
|
+
const errorData = toErrorData(error);
|
|
27
|
+
return { __is_job_transition__: true, type: "failed", error: errorData };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
logger("Runner").debug("Manual job resolution is disabled; importing specified job script.");
|
|
32
|
+
// Convert relative path to absolute file URL for dynamic import
|
|
33
|
+
scriptUrl = resolveScriptPath(jobData.script);
|
|
34
|
+
}
|
|
17
35
|
script = (await import(scriptUrl));
|
|
18
36
|
logger("Runner").debug(`Successfully imported job script "${jobData.script}"`);
|
|
19
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sources":["../../src/shared-runner/runner.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.js","sources":["../../src/shared-runner/runner.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKA;;;;;AAKG;AACY,eAAe,GAAG,CAAC,EAAE,OAAO,EAAE,MAAM,EAA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CAA4C,CAAC;AACpE,QAAA,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,eAAe,EAAE;AAC7C,QAAA,MAAM,SAAS,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;QAC7D,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,wCAAwC,CAAC;AAChE,QAAA,OAAO,IAAI;IACb;IAAE,OAAO,KAAK,EAAE;QACd,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CACnB,CAAA,mCAAA,EAAsC,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA,oBAAA,CAAsB,CACnH;AACD,QAAA,OAAO,KAAK;IACd;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sidequest/engine",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "@sidequest/engine is the core engine of SideQuest, a distributed background job processing system for Node.js and TypeScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nodejs",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
},
|
|
43
43
|
"license": "LGPL-3.0-or-later",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@sidequest/backend": "1.
|
|
46
|
-
"@sidequest/core": "1.
|
|
47
|
-
"node-cron": "^4.
|
|
48
|
-
"piscina": "^5.1.
|
|
45
|
+
"@sidequest/backend": "1.7.1",
|
|
46
|
+
"@sidequest/core": "1.7.1",
|
|
47
|
+
"node-cron": "^4.2.1",
|
|
48
|
+
"piscina": "^5.1.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"sidequest": "1.
|
|
51
|
+
"sidequest": "1.7.1"
|
|
52
52
|
}
|
|
53
53
|
}
|