@aomex/cron 3.30.7 → 3.30.8-alpha.62.sha-92b25bb

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/index.d.ts CHANGED
@@ -1,51 +1,51 @@
1
- import { ConsoleMiddleware } from '@aomex/console';
2
- import { Caching } from '@aomex/cache';
3
- import { GlobPathOptions } from '@aomex/internal-file-import';
4
-
5
- interface CronsOptions {
6
- commanders: GlobPathOptions;
7
- /**
8
- * 集群服务共享状态。默认使用内存缓存,只能约束当前进程
9
- */
10
- cache?: Caching;
11
- /**
12
- * 服务端口,用于查看任务状态和停止定时任务。默认值:`9786`
13
- */
14
- port?: number;
1
+ import { ConsoleMiddleware } from "@aomex/console";
2
+ import { GlobPathOptions } from "@aomex/internal-file-import";
3
+ import { CacheAdapter } from "@aomex/cache";
4
+ export interface CronsOptions {
5
+ commanders: GlobPathOptions;
6
+ /**
7
+ * 集群服务共享状态。默认使用内存存储,只能约束当前进程
8
+ */
9
+ store?: CacheAdapter;
10
+ /**
11
+ * 服务端口,用于查看任务状态和停止定时任务。有效范围:`1-65535`
12
+ */
13
+ port: number;
15
14
  }
16
- interface CronTimeObject {
17
- /**
18
- * 0-59
19
- */
20
- second?: string | number;
21
- /**
22
- * 0-59
23
- */
24
- minute?: string | number;
25
- /**
26
- * 0-23
27
- */
28
- hour?: string | number;
29
- /**
30
- * 1-31
31
- */
32
- dayOfMonth?: string | number;
33
- /**
34
- * 0-11
35
- */
36
- month?: string | number;
37
- /**
38
- * 0-6
39
- * - 周末: 0
40
- * - 周一: 1
41
- */
42
- dayOfWeek?: string | number;
15
+ export interface CronTimeObject {
16
+ /**
17
+ * 0-59
18
+ */
19
+ second?: string | number;
20
+ /**
21
+ * 0-59
22
+ */
23
+ minute?: string | number;
24
+ /**
25
+ * 0-23
26
+ */
27
+ hour?: string | number;
28
+ /**
29
+ * 1-31
30
+ */
31
+ dayOfMonth?: string | number;
32
+ /**
33
+ * 0-11
34
+ */
35
+ month?: string | number;
36
+ /**
37
+ * 0-6
38
+ * - 周末: 0
39
+ * - 周一: 1
40
+ */
41
+ dayOfWeek?: string | number;
43
42
  }
44
- interface CronTimeString {
45
- /**
43
+ export interface CronTimeString {
44
+ /**
46
45
  * 如果想验证时间表达式,可访问 https://crontab.guru
47
46
  *
48
- 类似linux下cron的时间格式,并支持秒级时间
47
+ * 类似 linux 下 cron 的时间格式,并支持秒级时间。必须是 **5 段**(分起)或 **6 段**(含秒);
48
+ * 更短的写法会被拒绝(cron-parser 会静默前补导致语义错乱)。
49
49
  ```
50
50
  ┌────────────── second (optional)
51
51
  │ ┌──────────── minute
@@ -57,90 +57,86 @@ interface CronTimeString {
57
57
  `* * * * * *`
58
58
  ```
59
59
  */
60
- time: string;
60
+ time: string;
61
61
  }
62
- type CronOptions = (CronTimeObject | CronTimeString) & {
62
+ export type CronOptions = (CronTimeObject | CronTimeString) & {
63
+ /**
64
+ * 执行时附带的参数,使用`options`接收
65
+ *
66
+ * 例子:`['--hello', 'world', '-it', '-o', 'file.txt']`
67
+ */
68
+ args?: (string | number)[];
69
+ /**
70
+ * 允许同时执行的任务数量,如果允许不同时间点的任务重叠执行,可以设置 >1 的值。
71
+ *
72
+ * 默认值:`1`
73
+ */
74
+ concurrent?: number | 'infinity';
75
+ /**
76
+ * 当同时执行的任务数量达到设定的`concurrent`值,新产生的任务会被放进等待池,并不断尝试获得执行权,直到超时被丢弃。
77
+ *
78
+ * 默认值:`10_000`
79
+ *
80
+ * 对于持续性任务`while (duration < 60_000) {...}`,我们不希望任务出现重叠。
81
+ * 但是因业务逻辑复杂程度不同,循环(while)没办法总是在指定的时间范围内结束。
82
+ * 任务一旦在新任务开始后才退出循环(while),就会导致新任务因并发检测失败而跳过执行。
83
+ */
84
+ waitingTimeout?: number;
85
+ };
86
+ export type ServerWriteData = {
87
+ runningPIDs: string[];
88
+ } | {
89
+ runners: {
90
+ pid: string;
91
+ command: string;
92
+ schedule: string;
93
+ }[];
94
+ };
95
+ export declare const crons: (opts: CronsOptions) => ConsoleMiddleware;
96
+ export interface CropProps {
97
+ readonly cron: {
63
98
  /**
64
- * 执行时附带的参数,使用`options`接收
65
- *
66
- * 例子:`['--hello', 'world', '-it', '-o', 'file.txt']`
99
+ * 计划执行的时间
67
100
  */
68
- args?: (string | number)[];
101
+ scheduleTime: Date;
69
102
  /**
70
- * 允许同时执行的任务数量,如果允许不同时间点的任务重叠执行,可以设置 >1 的值。
71
- *
72
- * 默认值:`1`
103
+ * 最终执行的时间
73
104
  */
74
- concurrent?: number | 'infinity';
105
+ executionTime: Date;
75
106
  /**
76
- * 当同时执行的任务数量达到设定的`concurrent`值,新产生的任务会被放进等待池,并不断尝试获得执行权,直到超时被丢弃。
77
- *
78
- * 默认值:`10_000`
107
+ * 下一个时间点计划执行的时间
108
+ */
109
+ nextScheduleTime: Date;
110
+ /**
111
+ * 是否可以持续执行任务,一般用于while循环不需要间断的逻辑。手动执行`aomex cron:stop`之后,返回值为`false`
79
112
  *
80
- * 对于持续性任务`while (duration < 60_000) {...}`,我们不希望任务出现重叠。
81
- * 但是因业务逻辑复杂程度不同,循环(while)没办法总是在指定的时间范围内结束。
82
- * 任务一旦在新任务开始后才退出循环(while),就会导致新任务因并发检测失败而跳过执行。
113
+ * ```
114
+ * commander.create('schedule', {
115
+ * mount: [cron({
116
+ * minute: '*',
117
+ * })],
118
+ * action: async (ctx) => {
119
+ * while (ctx.cron.isAlive()) {
120
+ * // 逻辑...
121
+ * }
122
+ * }
123
+ * });
124
+ * ```
83
125
  */
84
- waitingTimeout?: number;
85
- };
86
- type ServerWriteData = {
87
- runningPIDs: string[];
88
- } | {
89
- runners: {
90
- pid: string;
91
- command: string;
92
- schedule: string;
93
- }[];
94
- };
95
-
96
- declare const crons: (opts: CronsOptions) => ConsoleMiddleware;
97
-
98
- interface CropProps {
99
- readonly cron: {
100
- /**
101
- * 计划执行的时间
102
- */
103
- scheduleTime: Date;
104
- /**
105
- * 最终执行的时间
106
- */
107
- executionTime: Date;
108
- /**
109
- * 下一个时间点计划执行的时间
110
- */
111
- nextScheduleTime: Date;
112
- /**
113
- * 是否可以持续执行任务,一般用于while循环不需要间断的逻辑。手动执行`aomex cron:stop`之后,返回值为`false`
114
- *
115
- * ```
116
- * commander.create('schedule', {
117
- * mount: [cron({
118
- * minute: '*',
119
- * })],
120
- * action: async (ctx) => {
121
- * while (ctx.cron.isAlive()) {
122
- * // 逻辑...
123
- * }
124
- * }
125
- * });
126
- * ```
127
- */
128
- isAlive: (maxTimeoutMS?: number) => boolean;
129
- /**
130
- * 是否仍处于触发当前任务的时间段,即下一次任务还没出发。判断方式:`nextScheduleTime > now`
131
- */
132
- isCurrentEpoch: () => boolean;
133
- };
126
+ isAlive: (maxTimeoutMS?: number) => boolean;
127
+ /**
128
+ * 是否仍处于触发当前任务的时间段,即下一次任务还没出发。判断方式:`nextScheduleTime > now`
129
+ */
130
+ isCurrentEpoch: () => boolean;
131
+ };
134
132
  }
135
- declare class CronMiddleware extends ConsoleMiddleware<CropProps> {
136
- protected readonly options: CronOptions;
137
- constructor(options: CronOptions);
133
+ export declare class CronMiddleware extends ConsoleMiddleware<CropProps> {
134
+ protected readonly options: CronOptions;
135
+ constructor(options: CronOptions);
138
136
  }
139
137
  /**
140
138
  * 收集定时任务
141
139
  *
142
140
  * 如果传递字符串,则为cron时间表达式(支持秒)。如:`1-10,20 * * * *`
143
141
  */
144
- declare const cron: (options: CronOptions | string) => CronMiddleware;
145
-
146
- export { CronMiddleware, type CronOptions, type CronTimeObject, type CronTimeString, type CronsOptions, type CropProps, type ServerWriteData, cron, crons };
142
+ export declare const cron: (options: CronOptions | string) => CronMiddleware;