@h-ai/scheduler 0.1.0-alpha.53 → 0.1.0-alpha.55
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/README.md +14 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +286 -118
- package/dist/index.js.map +1 -1
- package/dist/scheduler-js-worker.d.ts +22 -0
- package/dist/scheduler-js-worker.js +20 -0
- package/dist/scheduler-js-worker.js.map +1 -0
- package/package.json +9 -5
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Script } from 'node:vm';
|
|
2
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
3
|
+
|
|
4
|
+
/** JS 任务只在独立线程执行;主线程负责期限和终止。此线程不是安全沙箱。 */
|
|
5
|
+
|
|
6
|
+
// 保持线程存活,使永不完成的 Promise 也由主线程统一超时终止。
|
|
7
|
+
parentPort.on('message', () => {});
|
|
8
|
+
|
|
9
|
+
async function run() {
|
|
10
|
+
try {
|
|
11
|
+
const candidate = new Script(`(${workerData.code})`).runInNewContext({});
|
|
12
|
+
if (typeof candidate !== 'function')
|
|
13
|
+
throw new TypeError('JS task code must evaluate to a function')
|
|
14
|
+
const result = await candidate(workerData.context);
|
|
15
|
+
parentPort.postMessage({ success: true, data: result });
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
parentPort.postMessage({ success: false, message: error instanceof Error ? error.message : String(error) });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void run();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Script } from 'vm';
|
|
2
|
+
import { parentPort, workerData } from 'worker_threads';
|
|
3
|
+
|
|
4
|
+
// src/scheduler-js-worker.js
|
|
5
|
+
parentPort.on("message", () => {
|
|
6
|
+
});
|
|
7
|
+
async function run() {
|
|
8
|
+
try {
|
|
9
|
+
const candidate = new Script(`(${workerData.code})`).runInNewContext({});
|
|
10
|
+
if (typeof candidate !== "function")
|
|
11
|
+
throw new TypeError("JS task code must evaluate to a function");
|
|
12
|
+
const result = await candidate(workerData.context);
|
|
13
|
+
parentPort.postMessage({ success: true, data: result });
|
|
14
|
+
} catch (error) {
|
|
15
|
+
parentPort.postMessage({ success: false, message: error instanceof Error ? error.message : String(error) });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
void run();
|
|
19
|
+
//# sourceMappingURL=scheduler-js-worker.js.map
|
|
20
|
+
//# sourceMappingURL=scheduler-js-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/scheduler-js-worker.js"],"names":[],"mappings":";;;;AAKA,UAAA,CAAW,EAAA,CAAG,WAAW,MAAM;AAAC,CAAC,CAAA;AAEjC,eAAe,GAAA,GAAM;AACnB,EAAA,IAAI;AACF,IAAA,MAAM,SAAA,GAAY,IAAI,MAAA,CAAO,CAAA,CAAA,EAAI,UAAA,CAAW,IAAI,CAAA,CAAA,CAAG,CAAA,CAAE,eAAA,CAAgB,EAAE,CAAA;AACvE,IAAA,IAAI,OAAO,SAAA,KAAc,UAAA;AACvB,MAAA,MAAM,IAAI,UAAU,0CAA0C,CAAA;AAChE,IAAA,MAAM,MAAA,GAAS,MAAM,SAAA,CAAU,UAAA,CAAW,OAAO,CAAA;AACjD,IAAA,UAAA,CAAW,YAAY,EAAE,OAAA,EAAS,IAAA,EAAM,IAAA,EAAM,QAAQ,CAAA;AAAA,EACxD,SACO,KAAA,EAAO;AACZ,IAAA,UAAA,CAAW,WAAA,CAAY,EAAE,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CAAA,EAAG,CAAA;AAAA,EAC5G;AACF;AAEA,KAAK,GAAA,EAAI","file":"scheduler-js-worker.js","sourcesContent":["/** JS 任务只在独立线程执行;主线程负责期限和终止。此线程不是安全沙箱。 */\nimport { Script } from 'node:vm'\nimport { parentPort, workerData } from 'node:worker_threads'\n\n// 保持线程存活,使永不完成的 Promise 也由主线程统一超时终止。\nparentPort.on('message', () => {})\n\nasync function run() {\n try {\n const candidate = new Script(`(${workerData.code})`).runInNewContext({})\n if (typeof candidate !== 'function')\n throw new TypeError('JS task code must evaluate to a function')\n const result = await candidate(workerData.context)\n parentPort.postMessage({ success: true, data: result })\n }\n catch (error) {\n parentPort.postMessage({ success: false, message: error instanceof Error ? error.message : String(error) })\n }\n}\n\nvoid run()\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-ai/scheduler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.0-alpha.
|
|
4
|
+
"version": "0.1.0-alpha.55",
|
|
5
5
|
"description": "Hai Framework task scheduling module with cron, function, and API jobs.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"exports": {
|
|
@@ -19,12 +19,15 @@
|
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22.12.0"
|
|
24
|
+
},
|
|
22
25
|
"dependencies": {
|
|
23
26
|
"croner": "^10.0.1",
|
|
24
27
|
"zod": "^4.4.3",
|
|
25
|
-
"@h-ai/
|
|
26
|
-
"@h-ai/
|
|
27
|
-
"@h-ai/reldb": "0.1.0-alpha.
|
|
28
|
+
"@h-ai/cache": "0.1.0-alpha.55",
|
|
29
|
+
"@h-ai/core": "0.1.0-alpha.55",
|
|
30
|
+
"@h-ai/reldb": "0.1.0-alpha.55"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
33
|
"@types/node": "^25.9.1",
|
|
@@ -41,6 +44,7 @@
|
|
|
41
44
|
"typecheck": "tsc --noEmit",
|
|
42
45
|
"lint": "eslint .",
|
|
43
46
|
"lint:fix": "eslint . --fix",
|
|
44
|
-
"clean": "rimraf dist .turbo"
|
|
47
|
+
"clean": "rimraf dist .turbo",
|
|
48
|
+
"build:clean": "rimraf dist"
|
|
45
49
|
}
|
|
46
50
|
}
|