@eggjs/schedule 6.0.0-beta.19 → 6.0.0-beta.20

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.
Files changed (49) hide show
  1. package/dist/agent-BiclCXUu.js +32 -0
  2. package/dist/agent-DUNNeo72.d.ts +100 -0
  3. package/dist/agent.d.ts +3 -1
  4. package/dist/agent.js +4 -2
  5. package/dist/all-DY7LEzzF.js +11 -0
  6. package/dist/app/extend/agent.d.ts +3 -21
  7. package/dist/app/extend/agent.js +5 -30
  8. package/dist/app/extend/application.d.ts +3 -11
  9. package/dist/app/extend/application.js +3 -16
  10. package/dist/app/extend/application.unittest.d.ts +4 -7
  11. package/dist/app/extend/application.unittest.js +4 -44
  12. package/dist/app.d.ts +3 -1
  13. package/dist/application-Be3vYRp0.d.ts +22 -0
  14. package/dist/application-CtPD5smr.js +18 -0
  15. package/dist/application.unittest-BySM_r-a.js +46 -0
  16. package/dist/application.unittest-DOurfxcE.d.ts +8 -0
  17. package/dist/base-BQ53Qv2t.js +73 -0
  18. package/dist/config/config.default.d.ts +1 -19
  19. package/dist/config.default-Oe7rctMS.d.ts +20 -0
  20. package/dist/index.d.ts +6 -6
  21. package/dist/index.js +10 -5
  22. package/dist/lib/load_schedule.d.ts +2 -1
  23. package/dist/lib/load_schedule.js +1 -59
  24. package/dist/lib/schedule.d.ts +3 -34
  25. package/dist/lib/schedule.js +2 -75
  26. package/dist/lib/schedule_worker.d.ts +3 -13
  27. package/dist/lib/schedule_worker.js +2 -20
  28. package/dist/lib/strategy/all.d.ts +3 -1
  29. package/dist/lib/strategy/all.js +3 -9
  30. package/dist/lib/strategy/base.d.ts +3 -35
  31. package/dist/lib/strategy/base.js +1 -71
  32. package/dist/lib/strategy/timer.d.ts +3 -23
  33. package/dist/lib/strategy/timer.js +2 -69
  34. package/dist/lib/strategy/worker.d.ts +3 -1
  35. package/dist/lib/strategy/worker.js +3 -9
  36. package/dist/lib/types.d.ts +2 -20
  37. package/dist/lib/types.js +2 -0
  38. package/dist/load_schedule-BwGbsGkz.js +61 -0
  39. package/dist/schedule-C0pZBoiR.js +77 -0
  40. package/dist/schedule_worker-DsbRF__K.js +22 -0
  41. package/dist/timer-B-5D2wim.js +71 -0
  42. package/dist/types-C43iyhAd.js +1 -0
  43. package/dist/types-CPNMyF89.js +1 -0
  44. package/dist/types-D3XkzB3g.d.ts +21 -0
  45. package/dist/types-VUtK3imu.d.ts +17 -0
  46. package/dist/types.d.ts +2 -17
  47. package/dist/types.js +2 -0
  48. package/dist/worker-Dc570kZo.js +11 -0
  49. package/package.json +6 -6
@@ -0,0 +1,32 @@
1
+ import { BaseStrategy } from "./base-BQ53Qv2t.js";
2
+ import { TimerStrategy } from "./timer-B-5D2wim.js";
3
+ import { Schedule } from "./schedule-C0pZBoiR.js";
4
+ import { Agent } from "egg";
5
+
6
+ //#region src/app/extend/agent.ts
7
+ const SCHEDULE = Symbol("agent schedule");
8
+ var ScheduleAgent = class extends Agent {
9
+ /**
10
+ * @member agent#ScheduleStrategy
11
+ */
12
+ get ScheduleStrategy() {
13
+ return BaseStrategy;
14
+ }
15
+ /**
16
+ * @member agent#TimerScheduleStrategy
17
+ */
18
+ get TimerScheduleStrategy() {
19
+ return TimerStrategy;
20
+ }
21
+ /**
22
+ * @member agent#schedule
23
+ */
24
+ get schedule() {
25
+ let schedule = this[SCHEDULE];
26
+ if (!schedule) this[SCHEDULE] = schedule = new Schedule(this);
27
+ return schedule;
28
+ }
29
+ };
30
+
31
+ //#endregion
32
+ export { ScheduleAgent };
@@ -0,0 +1,100 @@
1
+ import { EggScheduleConfig } from "./config.default-Oe7rctMS.js";
2
+ import { EggScheduleItem, EggScheduleJobInfo } from "./types-D3XkzB3g.js";
3
+ import { CronExpression } from "cron-parser";
4
+ import safeTimers from "safe-timers";
5
+ import { Agent, EggLogger } from "egg";
6
+
7
+ //#region src/lib/strategy/base.d.ts
8
+ declare class BaseStrategy {
9
+ protected agent: ScheduleAgent;
10
+ protected scheduleConfig: EggScheduleConfig;
11
+ protected key: string;
12
+ protected logger: EggLogger;
13
+ protected closed: boolean;
14
+ count: number;
15
+ constructor(scheduleConfig: EggScheduleConfig, agent: ScheduleAgent, key: string);
16
+ /** keep compatibility */
17
+ get schedule(): EggScheduleConfig;
18
+ start(): Promise<void>;
19
+ close(): Promise<void>;
20
+ onJobStart(_info: EggScheduleJobInfo): void;
21
+ onJobFinish(_info: EggScheduleJobInfo): void;
22
+ /**
23
+ * trigger one worker
24
+ *
25
+ * @param {...any} args - pass to job task
26
+ */
27
+ sendOne(...args: any[]): void;
28
+ /**
29
+ * trigger all worker
30
+ *
31
+ * @param {...any} args - pass to job task
32
+ */
33
+ sendAll(...args: any[]): void;
34
+ getSeqId(): string;
35
+ }
36
+ //#endregion
37
+ //#region src/lib/strategy/timer.d.ts
38
+ declare abstract class TimerStrategy extends BaseStrategy {
39
+ #private;
40
+ protected cronInstance?: CronExpression;
41
+ constructor(scheduleConfig: EggScheduleConfig, agent: ScheduleAgent, key: string);
42
+ protected handler(): void;
43
+ start(): Promise<void>;
44
+ onJobStart(): void;
45
+ /**
46
+ * calculate next tick
47
+ *
48
+ * @return {Number|undefined} time interval, if out of range then return `undefined`
49
+ */
50
+ protected getNextTick(): number | undefined;
51
+ protected safeTimeout(handler: () => void, delay: number, ...args: any[]): number | safeTimers.Timeout;
52
+ }
53
+ //#endregion
54
+ //#region src/lib/schedule.d.ts
55
+ declare class Schedule {
56
+ #private;
57
+ closed: boolean;
58
+ constructor(agent: ScheduleAgent);
59
+ /**
60
+ * register a custom Schedule Strategy
61
+ * @param {String} type - strategy type
62
+ * @param {Strategy} clz - Strategy class
63
+ */
64
+ use(type: string, clz: typeof BaseStrategy): void;
65
+ /**
66
+ * load all schedule jobs, then initialize and register special strategy
67
+ */
68
+ init(): Promise<void>;
69
+ registerSchedule(scheduleItem: EggScheduleItem): void;
70
+ unregisterSchedule(key: string): boolean;
71
+ /**
72
+ * job finish event handler
73
+ *
74
+ * @param {Object} info - { id, key, success, message, workerId }
75
+ */
76
+ onJobFinish(info: EggScheduleJobInfo): void;
77
+ /**
78
+ * start schedule
79
+ */
80
+ start(): Promise<void>;
81
+ close(): Promise<void>;
82
+ }
83
+ //#endregion
84
+ //#region src/app/extend/agent.d.ts
85
+ declare class ScheduleAgent extends Agent {
86
+ /**
87
+ * @member agent#ScheduleStrategy
88
+ */
89
+ get ScheduleStrategy(): typeof BaseStrategy;
90
+ /**
91
+ * @member agent#TimerScheduleStrategy
92
+ */
93
+ get TimerScheduleStrategy(): typeof TimerStrategy;
94
+ /**
95
+ * @member agent#schedule
96
+ */
97
+ get schedule(): Schedule;
98
+ }
99
+ //#endregion
100
+ export { BaseStrategy, Schedule, ScheduleAgent, TimerStrategy };
package/dist/agent.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import ScheduleAgent from "./app/extend/agent.js";
1
+ import "./config.default-Oe7rctMS.js";
2
+ import "./types-D3XkzB3g.js";
3
+ import { ScheduleAgent } from "./agent-DUNNeo72.js";
2
4
  import { ILifecycleBoot } from "egg";
3
5
 
4
6
  //#region src/agent.d.ts
package/dist/agent.js CHANGED
@@ -1,5 +1,7 @@
1
- import { WorkerStrategy } from "./lib/strategy/worker.js";
2
- import { AllStrategy } from "./lib/strategy/all.js";
1
+ import "./base-BQ53Qv2t.js";
2
+ import "./timer-B-5D2wim.js";
3
+ import { WorkerStrategy } from "./worker-Dc570kZo.js";
4
+ import { AllStrategy } from "./all-DY7LEzzF.js";
3
5
  import { debuglog } from "node:util";
4
6
 
5
7
  //#region src/agent.ts
@@ -0,0 +1,11 @@
1
+ import { TimerStrategy } from "./timer-B-5D2wim.js";
2
+
3
+ //#region src/lib/strategy/all.ts
4
+ var AllStrategy = class extends TimerStrategy {
5
+ handler() {
6
+ this.sendAll();
7
+ }
8
+ };
9
+
10
+ //#endregion
11
+ export { AllStrategy };
@@ -1,22 +1,4 @@
1
- import { BaseStrategy } from "../../lib/strategy/base.js";
2
- import { TimerStrategy } from "../../lib/strategy/timer.js";
3
- import { Schedule } from "../../lib/schedule.js";
4
- import { Agent } from "egg";
5
-
6
- //#region src/app/extend/agent.d.ts
7
- declare class ScheduleAgent extends Agent {
8
- /**
9
- * @member agent#ScheduleStrategy
10
- */
11
- get ScheduleStrategy(): typeof BaseStrategy;
12
- /**
13
- * @member agent#TimerScheduleStrategy
14
- */
15
- get TimerScheduleStrategy(): typeof TimerStrategy;
16
- /**
17
- * @member agent#schedule
18
- */
19
- get schedule(): Schedule;
20
- }
21
- //#endregion
1
+ import "../../config.default-Oe7rctMS.js";
2
+ import "../../types-D3XkzB3g.js";
3
+ import { ScheduleAgent } from "../../agent-DUNNeo72.js";
22
4
  export { ScheduleAgent as default };
@@ -1,32 +1,7 @@
1
- import { BaseStrategy } from "../../lib/strategy/base.js";
2
- import { TimerStrategy } from "../../lib/strategy/timer.js";
3
- import { Schedule } from "../../lib/schedule.js";
4
- import { Agent } from "egg";
1
+ import "../../base-BQ53Qv2t.js";
2
+ import "../../timer-B-5D2wim.js";
3
+ import "../../load_schedule-BwGbsGkz.js";
4
+ import "../../schedule-C0pZBoiR.js";
5
+ import { ScheduleAgent } from "../../agent-BiclCXUu.js";
5
6
 
6
- //#region src/app/extend/agent.ts
7
- const SCHEDULE = Symbol("agent schedule");
8
- var ScheduleAgent = class extends Agent {
9
- /**
10
- * @member agent#ScheduleStrategy
11
- */
12
- get ScheduleStrategy() {
13
- return BaseStrategy;
14
- }
15
- /**
16
- * @member agent#TimerScheduleStrategy
17
- */
18
- get TimerScheduleStrategy() {
19
- return TimerStrategy;
20
- }
21
- /**
22
- * @member agent#schedule
23
- */
24
- get schedule() {
25
- let schedule = this[SCHEDULE];
26
- if (!schedule) this[SCHEDULE] = schedule = new Schedule(this);
27
- return schedule;
28
- }
29
- };
30
-
31
- //#endregion
32
7
  export { ScheduleAgent as default };
@@ -1,12 +1,4 @@
1
- import { ScheduleWorker } from "../../lib/schedule_worker.js";
2
- import { Application } from "egg";
3
-
4
- //#region src/app/extend/application.d.ts
5
- declare class ScheduleApplication extends Application {
6
- /**
7
- * @member app#schedule
8
- */
9
- get scheduleWorker(): ScheduleWorker;
10
- }
11
- //#endregion
1
+ import "../../config.default-Oe7rctMS.js";
2
+ import "../../types-D3XkzB3g.js";
3
+ import { ScheduleApplication } from "../../application-Be3vYRp0.js";
12
4
  export { ScheduleApplication as default };
@@ -1,18 +1,5 @@
1
- import { ScheduleWorker } from "../../lib/schedule_worker.js";
2
- import { Application } from "egg";
1
+ import "../../load_schedule-BwGbsGkz.js";
2
+ import "../../schedule_worker-DsbRF__K.js";
3
+ import { ScheduleApplication } from "../../application-CtPD5smr.js";
3
4
 
4
- //#region src/app/extend/application.ts
5
- const SCHEDULE_WORKER = Symbol("application scheduleWorker");
6
- var ScheduleApplication = class extends Application {
7
- /**
8
- * @member app#schedule
9
- */
10
- get scheduleWorker() {
11
- let scheduleWorker = this[SCHEDULE_WORKER];
12
- if (!scheduleWorker) this[SCHEDULE_WORKER] = scheduleWorker = new ScheduleWorker(this);
13
- return scheduleWorker;
14
- }
15
- };
16
-
17
- //#endregion
18
5
  export { ScheduleApplication as default };
@@ -1,8 +1,5 @@
1
- import ScheduleApplication from "./application.js";
2
-
3
- //#region src/app/extend/application.unittest.d.ts
4
- declare class ScheduleApplicationUnittest extends ScheduleApplication {
5
- runSchedule(schedulePath: string, ...args: any[]): Promise<void>;
6
- }
7
- //#endregion
1
+ import "../../config.default-Oe7rctMS.js";
2
+ import "../../types-D3XkzB3g.js";
3
+ import "../../application-Be3vYRp0.js";
4
+ import { ScheduleApplicationUnittest } from "../../application.unittest-DOurfxcE.js";
8
5
  export { ScheduleApplicationUnittest as default };
@@ -1,46 +1,6 @@
1
- import ScheduleApplication from "./application.js";
2
- import { debuglog } from "node:util";
3
- import path from "node:path";
4
- import { importResolve } from "@eggjs/utils";
1
+ import "../../load_schedule-BwGbsGkz.js";
2
+ import "../../schedule_worker-DsbRF__K.js";
3
+ import "../../application-CtPD5smr.js";
4
+ import { ScheduleApplicationUnittest } from "../../application.unittest-BySM_r-a.js";
5
5
 
6
- //#region src/app/extend/application.unittest.ts
7
- const debug = debuglog("egg/schedule/app");
8
- var ScheduleApplicationUnittest = class extends ScheduleApplication {
9
- async runSchedule(schedulePath, ...args) {
10
- debug("[runSchedule] start schedulePath: %o, args: %o", schedulePath, args);
11
- const config = this.config;
12
- const directory = [path.join(config.baseDir, "app/schedule"), ...config.schedule.directory];
13
- if (path.isAbsolute(schedulePath)) schedulePath = importResolve(schedulePath);
14
- else for (const dir of directory) {
15
- const trySchedulePath = path.join(dir, schedulePath);
16
- try {
17
- schedulePath = importResolve(trySchedulePath);
18
- break;
19
- } catch (err) {
20
- debug("[runSchedule] importResolve %o error: %s", trySchedulePath, err);
21
- }
22
- }
23
- debug("[runSchedule] resolve schedulePath: %o", schedulePath);
24
- let schedule;
25
- try {
26
- schedule = this.scheduleWorker.scheduleItems[schedulePath];
27
- if (!schedule) {
28
- debug("[runSchedule] Cannot find schedule %o, scheduleItems: %o", schedulePath, this.scheduleWorker.scheduleItems);
29
- throw new TypeError(`Cannot find schedule ${schedulePath}`);
30
- }
31
- } catch (err) {
32
- err.message = `[@eggjs/schedule] ${err.message}`;
33
- throw err;
34
- }
35
- const ctx = this.createAnonymousContext({
36
- method: "SCHEDULE",
37
- url: `/__schedule?path=${schedulePath}&${schedule.scheduleQueryString}`
38
- });
39
- return await this.ctxStorage.run(ctx, async () => {
40
- return await schedule.task(ctx, ...args);
41
- });
42
- }
43
- };
44
-
45
- //#endregion
46
6
  export { ScheduleApplicationUnittest as default };
package/dist/app.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import ScheduleApplication from "./app/extend/application.js";
1
+ import "./config.default-Oe7rctMS.js";
2
+ import "./types-D3XkzB3g.js";
3
+ import { ScheduleApplication } from "./application-Be3vYRp0.js";
2
4
  import { ILifecycleBoot } from "egg";
3
5
 
4
6
  //#region src/app.d.ts
@@ -0,0 +1,22 @@
1
+ import { EggScheduleItem } from "./types-D3XkzB3g.js";
2
+ import { Application } from "egg";
3
+
4
+ //#region src/lib/schedule_worker.d.ts
5
+ declare class ScheduleWorker {
6
+ #private;
7
+ scheduleItems: Record<string, EggScheduleItem>;
8
+ constructor(app: ScheduleApplication);
9
+ init(): Promise<void>;
10
+ registerSchedule(scheduleItem: EggScheduleItem): void;
11
+ unregisterSchedule(key: string): void;
12
+ }
13
+ //#endregion
14
+ //#region src/app/extend/application.d.ts
15
+ declare class ScheduleApplication extends Application {
16
+ /**
17
+ * @member app#schedule
18
+ */
19
+ get scheduleWorker(): ScheduleWorker;
20
+ }
21
+ //#endregion
22
+ export { ScheduleApplication, ScheduleWorker };
@@ -0,0 +1,18 @@
1
+ import { ScheduleWorker } from "./schedule_worker-DsbRF__K.js";
2
+ import { Application } from "egg";
3
+
4
+ //#region src/app/extend/application.ts
5
+ const SCHEDULE_WORKER = Symbol("application scheduleWorker");
6
+ var ScheduleApplication = class extends Application {
7
+ /**
8
+ * @member app#schedule
9
+ */
10
+ get scheduleWorker() {
11
+ let scheduleWorker = this[SCHEDULE_WORKER];
12
+ if (!scheduleWorker) this[SCHEDULE_WORKER] = scheduleWorker = new ScheduleWorker(this);
13
+ return scheduleWorker;
14
+ }
15
+ };
16
+
17
+ //#endregion
18
+ export { ScheduleApplication };
@@ -0,0 +1,46 @@
1
+ import { ScheduleApplication } from "./application-CtPD5smr.js";
2
+ import { debuglog } from "node:util";
3
+ import path from "node:path";
4
+ import { importResolve } from "@eggjs/utils";
5
+
6
+ //#region src/app/extend/application.unittest.ts
7
+ const debug = debuglog("egg/schedule/app");
8
+ var ScheduleApplicationUnittest = class extends ScheduleApplication {
9
+ async runSchedule(schedulePath, ...args) {
10
+ debug("[runSchedule] start schedulePath: %o, args: %o", schedulePath, args);
11
+ const config = this.config;
12
+ const directory = [path.join(config.baseDir, "app/schedule"), ...config.schedule.directory];
13
+ if (path.isAbsolute(schedulePath)) schedulePath = importResolve(schedulePath);
14
+ else for (const dir of directory) {
15
+ const trySchedulePath = path.join(dir, schedulePath);
16
+ try {
17
+ schedulePath = importResolve(trySchedulePath);
18
+ break;
19
+ } catch (err) {
20
+ debug("[runSchedule] importResolve %o error: %s", trySchedulePath, err);
21
+ }
22
+ }
23
+ debug("[runSchedule] resolve schedulePath: %o", schedulePath);
24
+ let schedule;
25
+ try {
26
+ schedule = this.scheduleWorker.scheduleItems[schedulePath];
27
+ if (!schedule) {
28
+ debug("[runSchedule] Cannot find schedule %o, scheduleItems: %o", schedulePath, this.scheduleWorker.scheduleItems);
29
+ throw new TypeError(`Cannot find schedule ${schedulePath}`);
30
+ }
31
+ } catch (err) {
32
+ err.message = `[@eggjs/schedule] ${err.message}`;
33
+ throw err;
34
+ }
35
+ const ctx = this.createAnonymousContext({
36
+ method: "SCHEDULE",
37
+ url: `/__schedule?path=${schedulePath}&${schedule.scheduleQueryString}`
38
+ });
39
+ return await this.ctxStorage.run(ctx, async () => {
40
+ return await schedule.task(ctx, ...args);
41
+ });
42
+ }
43
+ };
44
+
45
+ //#endregion
46
+ export { ScheduleApplicationUnittest };
@@ -0,0 +1,8 @@
1
+ import { ScheduleApplication } from "./application-Be3vYRp0.js";
2
+
3
+ //#region src/app/extend/application.unittest.d.ts
4
+ declare class ScheduleApplicationUnittest extends ScheduleApplication {
5
+ runSchedule(schedulePath: string, ...args: any[]): Promise<void>;
6
+ }
7
+ //#endregion
8
+ export { ScheduleApplicationUnittest };
@@ -0,0 +1,73 @@
1
+ //#region src/lib/strategy/base.ts
2
+ var BaseStrategy = class {
3
+ agent;
4
+ scheduleConfig;
5
+ key;
6
+ logger;
7
+ closed = false;
8
+ count = 0;
9
+ constructor(scheduleConfig, agent, key) {
10
+ this.agent = agent;
11
+ this.key = key;
12
+ this.scheduleConfig = scheduleConfig;
13
+ this.logger = this.agent.getLogger("scheduleLogger");
14
+ }
15
+ /** keep compatibility */
16
+ get schedule() {
17
+ return this.scheduleConfig;
18
+ }
19
+ async start() {}
20
+ async close() {
21
+ this.closed = true;
22
+ }
23
+ onJobStart(_info) {}
24
+ onJobFinish(_info) {}
25
+ /**
26
+ * trigger one worker
27
+ *
28
+ * @param {...any} args - pass to job task
29
+ */
30
+ sendOne(...args) {
31
+ /* istanbul ignore next */
32
+ if (this.agent.schedule.closed) {
33
+ this.logger.warn(`${this.key} skip due to schedule closed`);
34
+ return;
35
+ }
36
+ this.count++;
37
+ const info = {
38
+ key: this.key,
39
+ id: this.getSeqId(),
40
+ args
41
+ };
42
+ this.logger.info(`[Job#${info.id}] ${info.key} triggered, send random by agent`);
43
+ this.agent.messenger.sendRandom("egg-schedule", info);
44
+ this.onJobStart(info);
45
+ }
46
+ /**
47
+ * trigger all worker
48
+ *
49
+ * @param {...any} args - pass to job task
50
+ */
51
+ sendAll(...args) {
52
+ /* istanbul ignore next */
53
+ if (this.agent.schedule.closed) {
54
+ this.logger.warn(`${this.key} skip due to schedule closed`);
55
+ return;
56
+ }
57
+ this.count++;
58
+ const info = {
59
+ key: this.key,
60
+ id: this.getSeqId(),
61
+ args
62
+ };
63
+ this.logger.info(`[Job#${info.id}] ${info.key} triggered, send all by agent`);
64
+ this.agent.messenger.send("egg-schedule", info);
65
+ this.onJobStart(info);
66
+ }
67
+ getSeqId() {
68
+ return `${Date.now()}${process.hrtime().join("")}${this.count}`;
69
+ }
70
+ };
71
+
72
+ //#endregion
73
+ export { BaseStrategy };
@@ -1,20 +1,2 @@
1
- import { ParserOptions } from "cron-parser";
2
- import { PartialEggConfig } from "egg";
3
-
4
- //#region src/config/config.default.d.ts
5
- interface EggScheduleConfig {
6
- type?: 'worker' | 'all';
7
- interval?: string | number;
8
- cron?: string;
9
- cronOptions?: ParserOptions;
10
- immediate?: boolean;
11
- disable?: boolean;
12
- env?: string[];
13
- /**
14
- * custom additional directory, full path
15
- */
16
- directory: string[];
17
- }
18
- declare const _default: PartialEggConfig;
19
- //#endregion
1
+ import { EggScheduleConfig, _default } from "../config.default-Oe7rctMS.js";
20
2
  export { EggScheduleConfig, _default as default };
@@ -0,0 +1,20 @@
1
+ import { ParserOptions } from "cron-parser";
2
+ import { PartialEggConfig } from "egg";
3
+
4
+ //#region src/config/config.default.d.ts
5
+ interface EggScheduleConfig {
6
+ type?: 'worker' | 'all';
7
+ interval?: string | number;
8
+ cron?: string;
9
+ cronOptions?: ParserOptions;
10
+ immediate?: boolean;
11
+ disable?: boolean;
12
+ env?: string[];
13
+ /**
14
+ * custom additional directory, full path
15
+ */
16
+ directory: string[];
17
+ }
18
+ declare const _default: PartialEggConfig;
19
+ //#endregion
20
+ export { EggScheduleConfig, _default };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { EggScheduleItem, EggScheduleJobInfo, EggScheduleTask } from "./lib/types.js";
2
- import { Schedule } from "./lib/schedule.js";
3
- import ScheduleAgent from "./app/extend/agent.js";
4
- import { ScheduleWorker } from "./lib/schedule_worker.js";
5
- import ScheduleApplication from "./app/extend/application.js";
6
- import ScheduleApplicationUnittest from "./app/extend/application.unittest.js";
1
+ import "./config.default-Oe7rctMS.js";
2
+ import { EggScheduleItem, EggScheduleJobInfo, EggScheduleTask } from "./types-D3XkzB3g.js";
3
+ import { Schedule, ScheduleAgent } from "./agent-DUNNeo72.js";
4
+ import { ScheduleApplication, ScheduleWorker } from "./application-Be3vYRp0.js";
5
+ import { ScheduleApplicationUnittest } from "./application.unittest-DOurfxcE.js";
6
+ import "./types-VUtK3imu.js";
7
7
  export { ScheduleAgent as Agent, ScheduleApplication as Application, ScheduleApplicationUnittest as ApplicationUnittest, EggScheduleItem, EggScheduleJobInfo, EggScheduleTask, Schedule, ScheduleWorker };
package/dist/index.js CHANGED
@@ -1,7 +1,12 @@
1
- import { Schedule } from "./lib/schedule.js";
2
- import ScheduleAgent from "./app/extend/agent.js";
3
- import { ScheduleWorker } from "./lib/schedule_worker.js";
4
- import ScheduleApplication from "./app/extend/application.js";
5
- import ScheduleApplicationUnittest from "./app/extend/application.unittest.js";
1
+ import "./base-BQ53Qv2t.js";
2
+ import "./timer-B-5D2wim.js";
3
+ import "./load_schedule-BwGbsGkz.js";
4
+ import { Schedule } from "./schedule-C0pZBoiR.js";
5
+ import { ScheduleAgent } from "./agent-BiclCXUu.js";
6
+ import { ScheduleWorker } from "./schedule_worker-DsbRF__K.js";
7
+ import { ScheduleApplication } from "./application-CtPD5smr.js";
8
+ import { ScheduleApplicationUnittest } from "./application.unittest-BySM_r-a.js";
9
+ import "./types-CPNMyF89.js";
10
+ import "./types-C43iyhAd.js";
6
11
 
7
12
  export { ScheduleAgent as Agent, ScheduleApplication as Application, ScheduleApplicationUnittest as ApplicationUnittest, Schedule, ScheduleWorker };
@@ -1,4 +1,5 @@
1
- import { EggScheduleItem } from "./types.js";
1
+ import "../config.default-Oe7rctMS.js";
2
+ import { EggScheduleItem } from "../types-D3XkzB3g.js";
2
3
  import { EggApplicationCore } from "egg";
3
4
 
4
5
  //#region src/lib/load_schedule.d.ts
@@ -1,61 +1,3 @@
1
- import assert from "node:assert";
2
- import path from "node:path";
3
- import { stringify } from "node:querystring";
4
- import { isClass, isFunction, isGeneratorFunction } from "is-type-of";
5
- import { importResolve } from "@eggjs/utils";
1
+ import { loadSchedule } from "../load_schedule-BwGbsGkz.js";
6
2
 
7
- //#region src/lib/load_schedule.ts
8
- function getScheduleLoader(app) {
9
- return class ScheduleLoader extends app.loader.FileLoader {
10
- async load() {
11
- const target = this.options.target;
12
- const items = await this.parse();
13
- for (const item of items) {
14
- const schedule = item.exports;
15
- const fullpath = item.fullpath;
16
- const scheduleConfig = schedule.schedule;
17
- assert(scheduleConfig, `schedule(${fullpath}): must have "schedule" and "task" properties`);
18
- assert(isClass(schedule) || isFunction(schedule.task), `schedule(${fullpath}: \`schedule.task\` should be function or \`schedule\` should be class`);
19
- let task;
20
- if (isClass(schedule)) {
21
- assert(!isGeneratorFunction(schedule.prototype.subscribe), `schedule(${fullpath}): "schedule" generator function is not support, should use async function instead`);
22
- task = async (ctx, ...args) => {
23
- return new schedule(ctx).subscribe(...args);
24
- };
25
- } else {
26
- assert(!isGeneratorFunction(schedule.task), `schedule(${fullpath}): "task" generator function is not support, should use async function instead`);
27
- task = schedule.task;
28
- }
29
- const env = app.config.env;
30
- const envList = schedule.schedule.env;
31
- if (Array.isArray(envList) && !envList.includes(env)) {
32
- app.coreLogger.info(`[@eggjs/schedule]: ignore schedule ${fullpath} due to \`schedule.env\` not match`);
33
- continue;
34
- }
35
- const realFullpath = importResolve(fullpath);
36
- target[realFullpath] = {
37
- schedule: scheduleConfig,
38
- scheduleQueryString: stringify(scheduleConfig),
39
- task,
40
- key: realFullpath
41
- };
42
- }
43
- return target;
44
- }
45
- };
46
- }
47
- async function loadSchedule(app) {
48
- const dirs = [...app.loader.getLoadUnits().map((unit) => path.join(unit.path, "app/schedule")), ...app.config.schedule.directory];
49
- const Loader = getScheduleLoader(app);
50
- const schedules = {};
51
- await new Loader({
52
- directory: dirs,
53
- target: schedules,
54
- inject: app
55
- }).load();
56
- Reflect.set(app, "schedules", schedules);
57
- return schedules;
58
- }
59
-
60
- //#endregion
61
3
  export { loadSchedule };