@eggjs/schedule-plugin 4.0.0-beta.36 → 4.0.1-beta.0
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/app.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Application, ILifecycleBoot } from "egg";
|
|
|
3
3
|
//#region src/app.d.ts
|
|
4
4
|
declare class ScheduleAppBootHook implements ILifecycleBoot {
|
|
5
5
|
private readonly app;
|
|
6
|
+
private readonly scheduleManager;
|
|
6
7
|
private readonly scheduleWorkerRegister;
|
|
7
8
|
private readonly scheduleWorkerLoadUnitHook;
|
|
8
9
|
private readonly schedulePrototypeHook;
|
package/dist/app.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ScheduleManager } from "./lib/ScheduleManager.js";
|
|
1
2
|
import { SchedulePrototypeHook } from "./lib/SchedulePrototypeHook.js";
|
|
2
3
|
import { ScheduleWorkerLoadUnitHook } from "./lib/ScheduleWorkerLoadUnitHook.js";
|
|
3
4
|
import { ScheduleWorkerRegister } from "./lib/ScheduleWorkerRegister.js";
|
|
@@ -5,12 +6,14 @@ import { ScheduleWorkerRegister } from "./lib/ScheduleWorkerRegister.js";
|
|
|
5
6
|
//#region src/app.ts
|
|
6
7
|
var ScheduleAppBootHook = class {
|
|
7
8
|
app;
|
|
9
|
+
scheduleManager;
|
|
8
10
|
scheduleWorkerRegister;
|
|
9
11
|
scheduleWorkerLoadUnitHook;
|
|
10
12
|
schedulePrototypeHook;
|
|
11
13
|
constructor(app) {
|
|
12
14
|
this.app = app;
|
|
13
|
-
this.
|
|
15
|
+
this.scheduleManager = new ScheduleManager(this.app);
|
|
16
|
+
this.scheduleWorkerRegister = new ScheduleWorkerRegister(this.scheduleManager);
|
|
14
17
|
this.scheduleWorkerLoadUnitHook = new ScheduleWorkerLoadUnitHook(this.scheduleWorkerRegister);
|
|
15
18
|
this.schedulePrototypeHook = new SchedulePrototypeHook();
|
|
16
19
|
}
|
|
@@ -19,6 +22,7 @@ var ScheduleAppBootHook = class {
|
|
|
19
22
|
this.app.eggPrototypeLifecycleUtil.registerLifecycle(this.schedulePrototypeHook);
|
|
20
23
|
}
|
|
21
24
|
async beforeClose() {
|
|
25
|
+
this.scheduleManager.unregisterAll();
|
|
22
26
|
this.app.loadUnitLifecycleUtil.deleteLifecycle(this.scheduleWorkerLoadUnitHook);
|
|
23
27
|
this.app.eggPrototypeLifecycleUtil.deleteLifecycle(this.schedulePrototypeHook);
|
|
24
28
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EggPrototype } from "@eggjs/metadata";
|
|
2
|
+
import { Application } from "egg";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/ScheduleManager.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Manager class to track registered schedules and handle cleanup
|
|
8
|
+
*/
|
|
9
|
+
declare class ScheduleManager {
|
|
10
|
+
private readonly app;
|
|
11
|
+
private readonly registeredSchedules;
|
|
12
|
+
constructor(app: Application);
|
|
13
|
+
/**
|
|
14
|
+
* Register a schedule and track it
|
|
15
|
+
*/
|
|
16
|
+
register(proto: EggPrototype, scheduleItem: {
|
|
17
|
+
schedule: object;
|
|
18
|
+
task: any;
|
|
19
|
+
key: string;
|
|
20
|
+
}): void;
|
|
21
|
+
/**
|
|
22
|
+
* Unregister a single schedule by prototype
|
|
23
|
+
*/
|
|
24
|
+
unregister(proto: EggPrototype): void;
|
|
25
|
+
/**
|
|
26
|
+
* Unregister all tracked schedules
|
|
27
|
+
* Called during app beforeClose
|
|
28
|
+
*/
|
|
29
|
+
unregisterAll(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Get the count of registered schedules
|
|
32
|
+
*/
|
|
33
|
+
get size(): number;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { ScheduleManager };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PrototypeUtil } from "@eggjs/core-decorator";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/ScheduleManager.ts
|
|
4
|
+
/**
|
|
5
|
+
* Manager class to track registered schedules and handle cleanup
|
|
6
|
+
*/
|
|
7
|
+
var ScheduleManager = class {
|
|
8
|
+
app;
|
|
9
|
+
registeredSchedules = /* @__PURE__ */ new Map();
|
|
10
|
+
constructor(app) {
|
|
11
|
+
this.app = app;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Register a schedule and track it
|
|
15
|
+
*/
|
|
16
|
+
register(proto, scheduleItem) {
|
|
17
|
+
const { key } = scheduleItem;
|
|
18
|
+
this.registeredSchedules.set(key, proto);
|
|
19
|
+
this.app.scheduleWorker.registerSchedule(scheduleItem);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Unregister a single schedule by prototype
|
|
23
|
+
*/
|
|
24
|
+
unregister(proto) {
|
|
25
|
+
const key = proto.getMetaData(PrototypeUtil.FILE_PATH);
|
|
26
|
+
if (this.registeredSchedules.has(key)) {
|
|
27
|
+
this.app.scheduleWorker.unregisterSchedule(key);
|
|
28
|
+
this.registeredSchedules.delete(key);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Unregister all tracked schedules
|
|
33
|
+
* Called during app beforeClose
|
|
34
|
+
*/
|
|
35
|
+
unregisterAll() {
|
|
36
|
+
for (const key of this.registeredSchedules.keys()) this.app.scheduleWorker.unregisterSchedule(key);
|
|
37
|
+
this.registeredSchedules.clear();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the count of registered schedules
|
|
41
|
+
*/
|
|
42
|
+
get size() {
|
|
43
|
+
return this.registeredSchedules.size;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { ScheduleManager };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { ScheduleManager } from "./ScheduleManager.js";
|
|
1
2
|
import { EggPrototype } from "@eggjs/metadata";
|
|
2
3
|
import { ScheduleMetadata } from "@eggjs/schedule-decorator";
|
|
3
|
-
import { Application } from "egg";
|
|
4
4
|
|
|
5
5
|
//#region src/lib/ScheduleWorkerRegister.d.ts
|
|
6
6
|
declare class ScheduleWorkerRegister {
|
|
7
|
-
private readonly
|
|
8
|
-
constructor(
|
|
7
|
+
private readonly scheduleManager;
|
|
8
|
+
constructor(scheduleManager: ScheduleManager);
|
|
9
9
|
register(proto: EggPrototype, metadata: ScheduleMetadata<object>): void;
|
|
10
10
|
}
|
|
11
11
|
//#endregion
|
|
@@ -7,21 +7,21 @@ import { PrototypeUtil } from "@eggjs/core-decorator";
|
|
|
7
7
|
//#region src/lib/ScheduleWorkerRegister.ts
|
|
8
8
|
const debug = debuglog("egg/tegg/plugin/schedule/ScheduleWorkerRegister");
|
|
9
9
|
var ScheduleWorkerRegister = class {
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
this.
|
|
10
|
+
scheduleManager;
|
|
11
|
+
constructor(scheduleManager) {
|
|
12
|
+
this.scheduleManager = scheduleManager;
|
|
13
13
|
}
|
|
14
14
|
register(proto, metadata) {
|
|
15
15
|
const task = eggScheduleAdapterFactory(proto, metadata);
|
|
16
16
|
const schedule = EggScheduleMetadataConvertor.convertToEggSchedule(metadata);
|
|
17
|
-
const
|
|
18
|
-
|
|
17
|
+
const key = proto.getMetaData(PrototypeUtil.FILE_PATH);
|
|
18
|
+
if (!key) throw new Error(`schedule prototype: ${proto.name} missing FILE_PATH metadata`);
|
|
19
|
+
this.scheduleManager.register(proto, {
|
|
19
20
|
schedule,
|
|
20
|
-
scheduleQueryString: "",
|
|
21
21
|
task,
|
|
22
|
-
key
|
|
22
|
+
key
|
|
23
23
|
});
|
|
24
|
-
debug("register schedule %s, config: %j",
|
|
24
|
+
debug("register schedule %s, config: %j", key, schedule);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/schedule-plugin",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1-beta.0",
|
|
4
4
|
"description": "schedule decorator plugin for egg",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"egg",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"./app": "./dist/app.js",
|
|
33
33
|
"./lib/EggScheduleAdapter": "./dist/lib/EggScheduleAdapter.js",
|
|
34
34
|
"./lib/EggScheduleMetadataConvertor": "./dist/lib/EggScheduleMetadataConvertor.js",
|
|
35
|
+
"./lib/ScheduleManager": "./dist/lib/ScheduleManager.js",
|
|
35
36
|
"./lib/SchedulePrototypeHook": "./dist/lib/SchedulePrototypeHook.js",
|
|
36
37
|
"./lib/ScheduleSubscriberRegister": "./dist/lib/ScheduleSubscriberRegister.js",
|
|
37
38
|
"./lib/ScheduleWorkerLoadUnitHook": "./dist/lib/ScheduleWorkerLoadUnitHook.js",
|
|
@@ -43,28 +44,28 @@
|
|
|
43
44
|
"access": "public"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@eggjs/core-decorator": "4.0.
|
|
47
|
-
"@eggjs/lifecycle": "4.0.
|
|
48
|
-
"@eggjs/
|
|
49
|
-
"@eggjs/
|
|
50
|
-
"@eggjs/
|
|
51
|
-
"@eggjs/tegg-runtime": "4.0.
|
|
52
|
-
"@eggjs/
|
|
47
|
+
"@eggjs/core-decorator": "4.0.1-beta.0",
|
|
48
|
+
"@eggjs/lifecycle": "4.0.1-beta.0",
|
|
49
|
+
"@eggjs/module-common": "4.0.1-beta.0",
|
|
50
|
+
"@eggjs/schedule-decorator": "4.0.1-beta.0",
|
|
51
|
+
"@eggjs/tegg-loader": "4.0.1-beta.0",
|
|
52
|
+
"@eggjs/tegg-runtime": "4.0.1-beta.0",
|
|
53
|
+
"@eggjs/metadata": "4.0.1-beta.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@types/node": "^24.10.2",
|
|
56
57
|
"typescript": "^5.9.3",
|
|
57
|
-
"@eggjs/mock": "7.0.
|
|
58
|
+
"@eggjs/mock": "7.0.1-beta.0",
|
|
59
|
+
"@eggjs/tegg": "4.0.1-beta.0",
|
|
60
|
+
"@eggjs/tegg-common-util": "4.0.1-beta.0",
|
|
61
|
+
"@eggjs/tegg-config": "4.0.1-beta.0",
|
|
58
62
|
"@eggjs/module-test-util": "4.0.0-beta.29",
|
|
59
|
-
"@eggjs/tegg-
|
|
60
|
-
"
|
|
61
|
-
"@eggjs/tegg-config": "4.0.0-beta.36",
|
|
62
|
-
"egg": "4.1.0-beta.36",
|
|
63
|
-
"@eggjs/tegg-plugin": "4.0.0-beta.36"
|
|
63
|
+
"@eggjs/tegg-plugin": "4.0.1-beta.0",
|
|
64
|
+
"egg": "4.1.1-beta.0"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
66
|
-
"@eggjs/tegg-plugin": "4.0.
|
|
67
|
-
"egg": "4.1.
|
|
67
|
+
"@eggjs/tegg-plugin": "4.0.1-beta.0",
|
|
68
|
+
"egg": "4.1.1-beta.0"
|
|
68
69
|
},
|
|
69
70
|
"engines": {
|
|
70
71
|
"node": ">=22.18.0"
|