@aomex/cron 0.0.26 → 0.0.28

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/CHANGELOG.md CHANGED
@@ -1,220 +1,10 @@
1
1
  # @aomex/cron
2
2
 
3
- ## 0.0.26
3
+ ## 0.0.28
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [[`c40d78d`](https://github.com/aomex/aomex/commit/c40d78d50be47862f6816bdb106b8ca721b6aba5)]:
8
- - @aomex/console@0.0.25
9
- - @aomex/commander@0.0.27
10
-
11
- ## 0.0.25
12
-
13
- ### Patch Changes
14
-
15
- - [`68f6aed`](https://github.com/aomex/aomex/commit/68f6aed9b78293e744c4d595684a6ec8803fe64f) Thanks [@geekact](https://github.com/geekact)! - feat(cron): default use MemoryCache as driver
16
-
17
- - [`fa18366`](https://github.com/aomex/aomex/commit/fa183669753005d64024267d483676a8509fe719) Thanks [@geekact](https://github.com/geekact)! - feat(cron): never silence job
18
-
19
- - Updated dependencies [[`d0ac2ba`](https://github.com/aomex/aomex/commit/d0ac2ba078252dcab9140212cf7d5f270a4d5d81)]:
20
- - @aomex/console@0.0.24
21
- - @aomex/commander@0.0.26
22
-
23
- ## 0.0.24
24
-
25
- ### Patch Changes
26
-
27
- - [`8adf36f`](https://github.com/aomex/aomex/commit/8adf36fd143524b210a4f6d374ad234038cb7305) Thanks [@geekact](https://github.com/geekact)! - refactor(cron)!: rename overlapping to overlap
28
-
29
- - [`429d2ff`](https://github.com/aomex/aomex/commit/429d2ff440b76135b2c0691e3ca414b52f6c1605) Thanks [@geekact](https://github.com/geekact)! - feat(cron): add option race for multiple servers
30
-
31
- - Updated dependencies [[`ddcec91`](https://github.com/aomex/aomex/commit/ddcec91803b00f35f7c55964d1a2d97c40a22c6e)]:
32
- - @aomex/core@0.0.20
33
- - @aomex/commander@0.0.25
34
- - @aomex/console@0.0.23
35
-
36
- ## 0.0.23
37
-
38
- ### Patch Changes
39
-
40
- - Updated dependencies [[`3c4b97a`](https://github.com/aomex/aomex/commit/3c4b97af49b075ced611b19c362b26b831440327), [`6cbc69b`](https://github.com/aomex/aomex/commit/6cbc69bfce9d03b4880b94f9ec0ee20c9ae937a8), [`6cdbdc0`](https://github.com/aomex/aomex/commit/6cdbdc0382daa9417ad27ed4641cc27214cbae31)]:
41
- - @aomex/console@0.0.22
42
- - @aomex/utility@0.0.7
43
- - @aomex/core@0.0.19
44
- - @aomex/commander@0.0.24
45
-
46
- ## 0.0.22
47
-
48
- ### Patch Changes
49
-
50
- - [`6238c7d`](https://github.com/aomex/aomex/commit/6238c7dd01dc1930148576e3013ca8e3a3bf62c3) Thanks [@geekact](https://github.com/geekact)! - fix(cron): never exit code while executing schedule
51
-
52
- - Updated dependencies []:
53
- - @aomex/core@0.0.18
54
- - @aomex/commander@0.0.23
55
- - @aomex/console@0.0.21
56
-
57
- ## 0.0.21
58
-
59
- ### Patch Changes
60
-
61
- - Updated dependencies [[`37946d2`](https://github.com/aomex/aomex/commit/37946d2b91a560c851fa21fa327b5b968b794862)]:
62
- - @aomex/utility@0.0.6
63
- - @aomex/commander@0.0.22
64
- - @aomex/console@0.0.20
65
- - @aomex/core@0.0.17
66
-
67
- ## 0.0.20
68
-
69
- ### Patch Changes
70
-
71
- - Updated dependencies [[`8a7d860`](https://github.com/aomex/aomex/commit/8a7d860872abacbdb19a6dc49d1158bbc46422ad)]:
72
- - @aomex/console@0.0.19
73
- - @aomex/commander@0.0.21
74
-
75
- ## 0.0.19
76
-
77
- ### Patch Changes
78
-
79
- - [`4a13285`](https://github.com/aomex/aomex/commit/4a132856f0a069aad0e389d4872372bfdf4074f0) Thanks [@geekact](https://github.com/geekact)! - feat(cron): support input string as path
80
-
81
- - [`8cbe6c6`](https://github.com/aomex/aomex/commit/8cbe6c604ca1a846f205b944196fdb67f8ea5bc6) Thanks [@geekact](https://github.com/geekact)! - refactor(cron)!: rename options.paths to path
82
-
83
- ## 0.0.18
84
-
85
- ### Patch Changes
86
-
87
- - Updated dependencies [[`2e7bda9`](https://github.com/aomex/aomex/commit/2e7bda9af7ef64faba48316e99d15637b85988c7)]:
88
- - @aomex/console@0.0.18
89
- - @aomex/commander@0.0.20
90
-
91
- ## 0.0.17
92
-
93
- ### Patch Changes
94
-
95
- - Updated dependencies [[`eb6b156`](https://github.com/aomex/aomex/commit/eb6b156f19ee59f94cab8f2e364abc7af84524b2)]:
96
- - @aomex/console@0.0.17
97
- - @aomex/commander@0.0.19
98
-
99
- ## 0.0.16
100
-
101
- ### Patch Changes
102
-
103
- - Updated dependencies []:
104
- - @aomex/core@0.0.16
105
- - @aomex/commander@0.0.18
106
- - @aomex/console@0.0.16
107
-
108
- ## 0.0.15
109
-
110
- ### Patch Changes
111
-
112
- - Updated dependencies []:
113
- - @aomex/core@0.0.15
114
- - @aomex/commander@0.0.17
115
- - @aomex/console@0.0.15
116
-
117
- ## 0.0.14
118
-
119
- ### Patch Changes
120
-
121
- - [`1bddd3d`](https://github.com/aomex/aomex/commit/1bddd3dd9be1dbf446cb4ba3866de50fff8d6d50) Thanks [@geekact](https://github.com/geekact)! - feat(cron): update thread alive time from 6s to 15s
122
-
123
- ## 0.0.13
124
-
125
- ### Patch Changes
126
-
127
- - [`0b32d0a`](https://github.com/aomex/aomex/commit/0b32d0ac7b0cb244ccc1877bbd0de323fa41e0c6) Thanks [@geekact](https://github.com/geekact)! - fix(cron): duplicated timer
128
-
129
- - [`f10b782`](https://github.com/aomex/aomex/commit/f10b7824a9d8097d7d98b742688635d19f08935c) Thanks [@geekact](https://github.com/geekact)! - feat(cron): support multiple threads
130
-
131
- - [`e3fbd47`](https://github.com/aomex/aomex/commit/e3fbd47ed12842a1fcf2721f7608ffb83f3ded1a) Thanks [@geekact](https://github.com/geekact)! - feat(cron): share queue with multiple threads
132
-
133
- - Updated dependencies [[`6f44cc3`](https://github.com/aomex/aomex/commit/6f44cc33cf6f2704e08bb80bbfb02e3336cf180c)]:
134
- - @aomex/commander@0.0.16
135
- - @aomex/core@0.0.14
136
- - @aomex/console@0.0.14
137
-
138
- ## 0.0.12
139
-
140
- ### Patch Changes
141
-
142
- - Updated dependencies [[`1ee022f`](https://github.com/aomex/aomex/commit/1ee022fdc674997086be70f76afb3e293fc804d6)]:
143
- - @aomex/commander@0.0.15
144
- - @aomex/core@0.0.13
145
- - @aomex/console@0.0.13
146
-
147
- ## 0.0.11
148
-
149
- ### Patch Changes
150
-
151
- - Updated dependencies [[`2d8082e`](https://github.com/aomex/aomex/commit/2d8082e5763bdcdbdb34ccbee40ce5bb4869dab8)]:
152
- - @aomex/commander@0.0.14
153
-
154
- ## 0.0.9
155
-
156
- ### Patch Changes
157
-
158
- - Updated dependencies [[`5e84bab`](https://github.com/aomex/aomex/commit/5e84bab8d9f0b27911730b17771bec8a881ef9bb), [`77039d8`](https://github.com/aomex/aomex/commit/77039d8819944f27662866aab238bde6778d9a6f)]:
159
- - @aomex/commander@0.0.12
160
- - @aomex/console@0.0.12
161
- - @aomex/core@0.0.12
162
-
163
- ## 0.0.8
164
-
165
- ### Patch Changes
166
-
167
- - Updated dependencies [[`92273f9`](https://github.com/aomex/aomex/commit/92273f913e38543f34f41ec5941ff43b6e1caaa9)]:
168
- - @aomex/core@0.0.11
169
- - @aomex/commander@0.0.11
170
- - @aomex/console@0.0.11
171
-
172
- ## 0.0.7
173
-
174
- ### Patch Changes
175
-
176
- - Updated dependencies []:
177
- - @aomex/core@0.0.10
178
- - @aomex/commander@0.0.10
179
- - @aomex/console@0.0.10
180
-
181
- ## 0.0.6
182
-
183
- ### Patch Changes
184
-
185
- - [`4daab53`](https://github.com/aomex/aomex/commit/4daab530f58f8027332eb8789f0e3584a4603e83) Thanks [@geekact](https://github.com/geekact)! - refactor: rename console-router to commander
186
-
187
- - Updated dependencies [[`fbb7ab2`](https://github.com/aomex/aomex/commit/fbb7ab2e6ec2a18e7ad8f018788523952049b6fd), [`4daab53`](https://github.com/aomex/aomex/commit/4daab530f58f8027332eb8789f0e3584a4603e83)]:
188
- - @aomex/utility@0.0.5
189
- - @aomex/commander@0.0.9
190
- - @aomex/console@0.0.9
191
- - @aomex/core@0.0.9
192
-
193
- ## 0.0.5
194
-
195
- ### Patch Changes
196
-
197
- - [`3077a1f`](https://github.com/aomex/aomex/commit/3077a1fd43f30cf9d21fa0bfb406427706f05b89) Thanks [@geekact](https://github.com/geekact)! - chore(cron): upgrade cron-parser from 4.7.1 to 4.8.1
198
-
199
- - Updated dependencies [[`b7313d5`](https://github.com/aomex/aomex/commit/b7313d56bdb93cabde8dc5b872a94b590f45b655), [`01f90ab`](https://github.com/aomex/aomex/commit/01f90abec716427b7ccde3ab566067a4ba3293c8), [`912ed81`](https://github.com/aomex/aomex/commit/912ed81c12a3ff12c13607732107dec66c586a38), [`6c6cda2`](https://github.com/aomex/aomex/commit/6c6cda26522176c44761a738f2bc106a1889497b)]:
200
- - @aomex/file-parser@0.0.5
201
- - @aomex/console@0.0.8
202
- - @aomex/commander@0.0.8
203
- - @aomex/core@0.0.8
204
-
205
- ## 0.0.3
206
-
207
- ### Patch Changes
208
-
209
- - [`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f) Thanks [@geekact](https://github.com/geekact)! - refactor: rename package helper to utility
210
-
211
- - [`fa14484`](https://github.com/aomex/aomex/commit/fa14484e35039e4b5ac9fb293648bdf214f7472d) Thanks [@geekact](https://github.com/geekact)! - feat(cron): support cron-like time literal
212
-
213
- - [`d193c19`](https://github.com/aomex/aomex/commit/d193c198e4951034224587bfe166b7e18eca74bd) Thanks [@geekact](https://github.com/geekact)! - fix(cron): run schedule at wrong time
214
-
215
- - Updated dependencies [[`589243d`](https://github.com/aomex/aomex/commit/589243da955f3e4296d30fdfe05eac0c45714281), [`24d45f0`](https://github.com/aomex/aomex/commit/24d45f02966cfd936d493de5844bcae73caa6d10), [`cab01c6`](https://github.com/aomex/aomex/commit/cab01c63d60e73a7e24018e6872080d5656c29e2), [`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f), [`b4b6528`](https://github.com/aomex/aomex/commit/b4b652844441d74b173d4fc54f8300c66ba6e44d), [`9866b9e`](https://github.com/aomex/aomex/commit/9866b9e63abb71e1197ff8002c38bac04a36dd62)]:
216
- - @aomex/file-parser@0.0.3
217
- - @aomex/commander@0.0.6
218
- - @aomex/console@0.0.6
219
- - @aomex/utility@0.0.4
220
- - @aomex/core@0.0.6
7
+ - Updated dependencies [[`6f7d706`](https://github.com/aomex/aomex/commit/6f7d7066c23711abdd149eb1c9a293ab8c4284a4), [`e7bf93c`](https://github.com/aomex/aomex/commit/e7bf93cee6896c61d0bf3eb0921151dc6c1bc107), [`818e840`](https://github.com/aomex/aomex/commit/818e840d36c7456a863fc071968b246c123c17f5)]:
8
+ - @aomex/core@0.0.22
9
+ - @aomex/commander@0.0.29
10
+ - @aomex/console@0.0.27
package/dist/index.d.ts CHANGED
@@ -1,68 +1,25 @@
1
1
  import { ConsoleChain, ConsoleMiddleware } from '@aomex/console';
2
- import { Cache } from '@aomex/core';
3
- import { PathToFileOptions } from '@aomex/utility';
2
+ import { PathToFileOptions, Cache } from '@aomex/core';
4
3
 
5
4
  interface CronOptions {
6
5
  path: PathToFileOptions;
7
6
  /**
8
- * Running schedule with multiple server. Defaults `MemoryCache`
9
- * - while race = `true`
10
- * - while overlap = `false`
11
- *
12
- * ```
13
- *
14
- * [job]
15
- * │
16
- * │ race?
17
- * │
18
- * N │ Y
19
- * ╭───────────┴───────────╮
20
- * │ │
21
- * │ │ driver?
22
- * │ │
23
- * │ N │ Y
24
- * [all win] ─────────────────┴──────────────╮
25
- * │ │
26
- * │ │
27
- * │ [one win]
28
- * │ │
29
- * ╰───────────┬──────────────────────────╯
30
- * │
31
- * │
32
- * │ overlap?
33
- * │
34
- * N │ Y
35
- * ╭───────────┴───────────╮
36
- * │ │
37
- * │ │ driver?
38
- * │ │
39
- * │ N │ Y
40
- * ├───────────────────────┴──────────────╮
41
- * │ │
42
- * │ │ previous finished?
43
- * │ │
44
- * │ N │ Y
45
- * │ ╭────────────────┴──────────────╮
46
- * │ │ │
47
- * │ │ │
48
- * │ [loop waiting] │
49
- * │ │ │
50
- * │ [finished] │
51
- * │ │ │
52
- * │ │ │
53
- * ╰───────────┬─────────┴───────────────────────────────╯
54
- * │
55
- * [run job]
56
- *
57
- * ```
7
+ * 设置集群服务,任务共享。默认值:`MemoryCache`
58
8
  */
59
9
  driver?: Cache;
60
10
  /**
61
- * If set to true, only one server can receive the job. Defaults `false`.
11
+ * 任务分配模式。默认值:`false`
12
+ * - true: 竞赛,只有一个服务可获得某个任务
13
+ * - false: 每个服务都可以获得某个任务
62
14
  */
63
15
  race?: boolean;
64
16
  /**
65
- * If set to false, current job will not start before previous job finished. Defaults `true`
17
+ * 任务重叠执行。默认值:`true`
18
+ * - true: 某个任务触发后立即执行。适合允许并发操作的场景
19
+ *
20
+ * - false: 当前被触发的任务,需要等上一次被触发的任务执行完毕后才能执行。场景:
21
+ * 防止数据相互覆盖,防止重复生成数据,防止重复发送通知
22
+ *
66
23
  */
67
24
  overlap?: boolean;
68
25
  }
@@ -91,14 +48,14 @@ interface ScheduleTimeObject {
91
48
  month?: string | number;
92
49
  /**
93
50
  * 0-6
94
- * - weekend: 0
95
- * - monday: 1
51
+ * - 周末: 0
52
+ * - 周一: 1
96
53
  */
97
54
  dayOfWeek?: string | number;
98
55
  }
99
56
  interface ScheduleTimeString {
100
57
  /**
101
- Cron-like time, support seconds.
58
+ 类似linux下cron的时间格式,并支持秒级时间
102
59
  ```
103
60
  ┌────────────── second (optional)
104
61
  │ ┌──────────── minute
@@ -114,17 +71,25 @@ interface ScheduleTimeString {
114
71
  }
115
72
  interface ScheduleBaseOptions {
116
73
  /**
117
- * Examples: `['--hello', 'world', '-it', '--output', 'file.txt']`
74
+ * 执行时附带的参数,使用`options`接收
75
+ *
76
+ * 例子:`['--hello', 'world', '-it', '-o', 'file.txt']`
118
77
  */
119
78
  args?: (string | number)[];
120
79
  /**
121
- * If set to true, only one server can receive the job. If not set, `cron.race` will be used.
80
+ * 任务分配模式。默认值:`cron.race`
81
+ * - true: 竞赛,只有一个服务可获得某个任务
82
+ * - false: 每个服务都可以获得某个任务
122
83
  *
123
84
  * @see CronOptions.race
124
85
  */
125
86
  race?: boolean;
126
87
  /**
127
- * If set to false, the job will not start before previous job finished. If not set, `cron.overlap` will be used.
88
+ * 任务重叠执行。默认值:`cron.overlap`
89
+ * - true: 某个任务触发后立即执行。适合允许并发操作的场景
90
+ *
91
+ * - false: 当前被触发的任务,需要等上一次被触发的任务执行完毕后才能执行。场景:
92
+ * 防止数据相互覆盖,防止重复生成数据,防止重复发送通知
128
93
  *
129
94
  * @see CronOptions.overlap
130
95
  */
package/dist/index.js CHANGED
@@ -3,18 +3,22 @@ import { chain as chain3 } from "@aomex/core";
3
3
 
4
4
  // src/middleware/eject.ts
5
5
  import { options } from "@aomex/console";
6
- import { chain, middleware as middleware2, rule } from "@aomex/core";
7
- import { chalk as chalk2 } from "@aomex/utility";
6
+ import {
7
+ chain,
8
+ chalk as chalk2,
9
+ middleware as middleware2,
10
+ rule
11
+ } from "@aomex/core";
8
12
  import { mkdir, writeFile } from "node:fs/promises";
9
13
  import path, { dirname } from "node:path";
10
14
 
11
15
  // src/lib/get-middleware-schedule.ts
12
16
  import { Commander } from "@aomex/commander";
13
- import { Chain } from "@aomex/core";
14
17
  import {
18
+ Chain,
15
19
  fileToModules,
16
20
  pathToFiles
17
- } from "@aomex/utility";
21
+ } from "@aomex/core";
18
22
 
19
23
  // src/middleware/schedule.ts
20
24
  import { ConsoleMiddleware } from "@aomex/console";
@@ -142,7 +146,7 @@ var getMiddlewareSchedule = async (paths) => {
142
146
  );
143
147
  const schedules = [];
144
148
  for (const commander of commanders) {
145
- for (const builder of Commander.getBuilders(commander)) {
149
+ for (const builder of commander["builders"]) {
146
150
  for (const middleware5 of Chain.flatten(builder.chain)) {
147
151
  if (middleware5 instanceof ScheduleMiddleware) {
148
152
  schedules.push(middleware5.getSchedule(builder.commands[0]));
@@ -155,8 +159,7 @@ var getMiddlewareSchedule = async (paths) => {
155
159
 
156
160
  // src/middleware/eject-to-help.ts
157
161
  import { scriptName as scriptName2 } from "@aomex/console";
158
- import { middleware } from "@aomex/core";
159
- import { chalk } from "@aomex/utility";
162
+ import { chalk, middleware } from "@aomex/core";
160
163
  var ejectToHelp = (commandName) => middleware.help(async (ctx, next) => {
161
164
  return ctx.cli.config({
162
165
  all(yargs) {
@@ -210,9 +213,8 @@ var eject = (paths) => chain.console.mount(ejectToHelp(exportCron)).mount(ejectR
210
213
  import { middleware as middleware4, chain as chain2, MemoryCache } from "@aomex/core";
211
214
 
212
215
  // src/middleware/run-to-help.ts
213
- import { middleware as middleware3 } from "@aomex/core";
216
+ import { chalk as chalk3, middleware as middleware3 } from "@aomex/core";
214
217
  import { scriptName as scriptName3 } from "@aomex/console";
215
- import { chalk as chalk3 } from "@aomex/utility";
216
218
  var runToHelp = (commandName) => middleware3.help(async (ctx, next) => {
217
219
  ctx.cli.config({
218
220
  all(yargs) {
@@ -228,7 +230,7 @@ var runToHelp = (commandName) => middleware3.help(async (ctx, next) => {
228
230
 
229
231
  // src/lib/job.ts
230
232
  import cronParser from "cron-parser";
231
- import { sleep } from "@aomex/utility";
233
+ import { sleep } from "@aomex/core";
232
234
  var Job = class {
233
235
  constructor(app, schedule2, driver, race) {
234
236
  this.app = app;
@@ -291,8 +293,8 @@ var Job = class {
291
293
  };
292
294
 
293
295
  // src/lib/job-in-order.ts
294
- import { sleep as sleep2 } from "@aomex/utility";
295
296
  import { hostname } from "node:os";
297
+ import { sleep as sleep2 } from "@aomex/core";
296
298
  var THREE_SECOND = 3 * 1e3;
297
299
  var TEN_SECOND = 10 * 1e3;
298
300
  var ONE_DAY = 3600 * 24 * 1e3;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/middleware/cron.ts","../src/middleware/eject.ts","../src/lib/get-middleware-schedule.ts","../src/middleware/schedule.ts","../src/lib/schedule.ts","../src/middleware/eject-to-help.ts","../src/middleware/run.ts","../src/middleware/run-to-help.ts","../src/lib/job.ts","../src/lib/job-in-order.ts"],"sourcesContent":["import type { ConsoleChain } from '@aomex/console';\nimport { Cache, chain } from '@aomex/core';\nimport type { PathToFileOptions } from '@aomex/utility';\nimport { eject } from './eject';\nimport { run } from './run';\n\nexport interface CronOptions {\n path: PathToFileOptions;\n /**\n * Running schedule with multiple server. Defaults `MemoryCache`\n * - while race = `true`\n * - while overlap = `false`\n *\n * ```\n *\n * [job]\n * │\n * │ race?\n * │\n * N │ Y\n * ╭───────────┴───────────╮\n * │ │\n * │ │ driver?\n * │ │\n * │ N │ Y\n * [all win] ─────────────────┴──────────────╮\n * │ │\n * │ │\n * │ [one win]\n * │ │\n * ╰───────────┬──────────────────────────╯\n * │\n * │\n * │ overlap?\n * │\n * N │ Y\n * ╭───────────┴───────────╮\n * │ │\n * │ │ driver?\n * │ │\n * │ N │ Y\n * ├───────────────────────┴──────────────╮\n * │ │\n * │ │ previous finished?\n * │ │\n * │ N │ Y\n * │ ╭────────────────┴──────────────╮\n * │ │ │\n * │ │ │\n * │ [loop waiting] │\n * │ │ │\n * │ [finished] │\n * │ │ │\n * │ │ │\n * ╰───────────┬─────────┴───────────────────────────────╯\n * │\n * [run job]\n *\n * ```\n */\n driver?: Cache;\n /**\n * If set to true, only one server can receive the job. Defaults `false`.\n */\n race?: boolean;\n /**\n * If set to false, current job will not start before previous job finished. Defaults `true`\n */\n overlap?: boolean;\n}\n\nexport const cron = (options: string | CronOptions): ConsoleChain => {\n const opts: CronOptions =\n typeof options === 'string' ? { path: options } : options;\n return chain.console.mount(run(opts)).mount(eject(opts.path));\n};\n","import { options } from '@aomex/console';\nimport { chain, Middleware, middleware, rule } from '@aomex/core';\nimport { chalk, type PathToFileOptions } from '@aomex/utility';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport path, { dirname } from 'node:path';\nimport { getMiddlewareSchedule } from '../lib/get-middleware-schedule';\nimport { ejectToHelp } from './eject-to-help';\n\nconst exportCron = 'cron:eject';\n\nexport const ejectRule = options(\n {\n output: rule.string().optional().docs({\n description: 'Export to specific file',\n }),\n },\n {\n output: ['o'],\n },\n);\n\nexport const eject = (paths: PathToFileOptions) =>\n chain.console\n .mount(ejectToHelp(exportCron))\n .mount(ejectRule)\n .mount(\n middleware.console<Middleware.Infer<typeof ejectRule>>(\n async (ctx, next) => {\n if (ctx.request.command !== exportCron) {\n Reflect.deleteProperty(ctx, 'options');\n return next();\n }\n\n ctx.response.commandMatched = true;\n\n const schedules = await getMiddlewareSchedule(paths);\n const crons = schedules\n .map((schedule) => schedule.toCrontab())\n .flat();\n\n const { output: outputToFile } = ctx.options;\n if (outputToFile) {\n const file = path.resolve(outputToFile);\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, crons.join('\\n'), {});\n console.log(`Crontab has been created: ${chalk.blue(file)}`);\n } else {\n console.log(crons.join('\\n'));\n }\n },\n ),\n );\n","import { Commander } from '@aomex/commander';\nimport { Chain } from '@aomex/core';\nimport {\n fileToModules,\n type PathToFileOptions,\n pathToFiles,\n} from '@aomex/utility';\nimport { ScheduleMiddleware } from '../middleware/schedule';\nimport type { Schedule } from './schedule';\n\nexport const getMiddlewareSchedule = async (paths: PathToFileOptions) => {\n const files = await pathToFiles(paths);\n const commanders = await fileToModules<Commander>(\n files,\n (item) => !!item && item instanceof Commander,\n );\n const schedules: Schedule[] = [];\n for (const commander of commanders) {\n for (const builder of Commander.getBuilders(commander)) {\n for (const middleware of Chain.flatten(builder.chain)) {\n if (middleware instanceof ScheduleMiddleware) {\n schedules.push(middleware.getSchedule(builder.commands[0]!));\n }\n }\n }\n }\n return schedules;\n};\n","import { ConsoleMiddleware } from '@aomex/console';\nimport { Schedule, type ScheduleOptions } from '../lib/schedule';\n\nexport class ScheduleMiddleware extends ConsoleMiddleware<object> {\n constructor(protected readonly options: ScheduleOptions) {\n super(async (_, next) => next());\n }\n\n getSchedule(command: string): Schedule {\n return new Schedule({ ...this.options, command });\n }\n}\n\nexport const schedule = (\n options: ScheduleOptions | string,\n): ScheduleMiddleware => {\n return new ScheduleMiddleware(\n typeof options === 'string' ? { time: options } : options,\n );\n};\n","import { scriptName } from '@aomex/console';\nimport parser from 'cron-parser';\nimport type { CronOptions } from '../middleware/cron';\n\ninterface ScheduleTimeObject {\n /**\n * 0-59\n */\n second?: string | number;\n /**\n * 0-59\n */\n minute?: string | number;\n /**\n * 0-23\n */\n hour?: string | number;\n /**\n * 1-31\n */\n dayOfMonth?: string | number;\n /**\n * 0-11\n */\n month?: string | number;\n /**\n * 0-6\n * - weekend: 0\n * - monday: 1\n */\n dayOfWeek?: string | number;\n}\n\ninterface ScheduleTimeString {\n /**\n Cron-like time, support seconds.\n ```\n ┌────────────── second (optional)\n │ ┌──────────── minute \n │ │ ┌────────── hour\n │ │ │ ┌──────── day of month\n │ │ │ │ ┌────── month\n │ │ │ │ │ ┌──── day of week\n │ │ │ │ │ │\n `* * * * * *`\n ```\n */\n time: string;\n}\n\ninterface ScheduleBaseOptions {\n /**\n * Examples: `['--hello', 'world', '-it', '--output', 'file.txt']`\n */\n args?: (string | number)[];\n /**\n * If set to true, only one server can receive the job. If not set, `cron.race` will be used.\n *\n * @see CronOptions.race\n */\n race?: boolean;\n /**\n * If set to false, the job will not start before previous job finished. If not set, `cron.overlap` will be used.\n *\n * @see CronOptions.overlap\n */\n overlap?: CronOptions['overlap'];\n}\n\nexport type ScheduleOptions = (ScheduleTimeObject | ScheduleTimeString) &\n ScheduleBaseOptions;\n\nexport class Schedule {\n protected _time?: string;\n protected _seconds?: number[];\n protected _argv?: string[];\n\n constructor(\n protected readonly options: ScheduleOptions & { command: string },\n ) {}\n\n public get overlap(): CronOptions['overlap'] | undefined {\n return this.options.overlap;\n }\n\n public get race(): CronOptions['race'] | undefined {\n return this.options.race;\n }\n\n public get time(): string {\n return (this._time ??= (() => {\n const { options } = this;\n if ('time' in options) {\n const timeList = options.time.split(/\\s+/);\n switch (timeList.length) {\n case 6:\n timeList.shift();\n return timeList.join(' ');\n case 5:\n return timeList.join(' ');\n default:\n throw new Error(`Invalid cron time: \"${options.time}\"`);\n }\n }\n\n return [\n options.minute ?? '*',\n options.hour ?? '*',\n options.dayOfMonth ?? '*',\n options.month ?? '*',\n options.dayOfWeek ?? '*',\n ].join(' ');\n })());\n }\n\n public get argv(): string[] {\n return (this._argv ??= [\n this.options.command,\n ...(this.options.args || []),\n ].map(String));\n }\n\n public get seconds(): number[] {\n return (this._seconds ??= (() => {\n const { options } = this;\n let second: string | undefined;\n\n if ('time' in options) {\n const timeList = options.time.split(/\\s+/);\n if (timeList.length === 6) {\n second = timeList[0]!;\n }\n } else {\n second = options.second?.toString();\n }\n\n if (!second) return [];\n const seconds: number[] = [];\n // second and minute are both 0-59\n const interval = parser.parseExpression(`${second} * * * *`);\n while (true) {\n const nextSecond = interval.next().getMinutes();\n if (seconds.includes(nextSecond)) break;\n seconds.push(nextSecond);\n }\n return seconds.sort((a, b) => a - b);\n })());\n }\n\n public toCrontab(): string[] {\n const script = [this.time];\n const crons: string[][] = [];\n\n for (const second of this.seconds) {\n crons.push(script.concat(`sleep ${second};`));\n }\n\n if (crons.length === 0) {\n crons.push(script);\n }\n\n return crons.map((time) => {\n const argv = this.argv.map((value) =>\n value.includes(' ') ? `\"${value}\"` : value,\n );\n return time.concat(['npx', scriptName, ...argv]).join(' ');\n });\n }\n\n toJSON() {\n return {\n time: this.time,\n seconds: this.seconds,\n argv: this.argv,\n race: this.race,\n overlap: this.overlap,\n };\n }\n}\n","import { HelpMiddleware, scriptName } from '@aomex/console';\nimport { middleware } from '@aomex/core';\nimport { chalk } from '@aomex/utility';\nimport { ejectRule } from './eject';\n\nexport const ejectToHelp = (commandName: string): HelpMiddleware =>\n middleware.help(async (ctx, next) => {\n return ctx.cli.config({\n all(yargs) {\n yargs.command(chalk.yellow(commandName), 'Create cron-compatibly list');\n },\n detail(yargs) {\n yargs.usage(`${scriptName} ${commandName} [options]`);\n ejectRule.toHelp(yargs);\n },\n next,\n detailCommand: commandName,\n });\n });\n","import { middleware, chain, MemoryCache } from '@aomex/core';\nimport { runToHelp } from './run-to-help';\nimport type { CronOptions } from './cron';\nimport { Job } from '../lib/job';\nimport { getMiddlewareSchedule } from '../lib/get-middleware-schedule';\nimport { JobInOrder } from '../lib/job-in-order';\nimport { Schedule } from '../lib/schedule';\nimport { ConsoleApp } from '@aomex/console';\n\nconst runCron = 'cron:run';\n\nexport const run = (cron: CronOptions, forever: boolean = true) =>\n chain.console.mount(runToHelp(runCron)).mount(\n middleware.console(async (ctx, next) => {\n if (ctx.request.command !== runCron) return next();\n ctx.response.commandMatched = true;\n const schedules = await getMiddlewareSchedule(cron.path);\n const promises = schedules.map((schedule) => {\n return createJob(ctx.app, schedule, cron).start();\n });\n // Almost never exit\n if (forever) {\n await Promise.all(promises);\n }\n }),\n );\n\nexport const createJob = (\n app: ConsoleApp,\n schedule: Schedule,\n cron: CronOptions,\n) => {\n const race = schedule.race ?? cron.race ?? false;\n const driver = cron.driver || new MemoryCache();\n const overlap = schedule.overlap ?? cron.overlap ?? true;\n return overlap\n ? new Job(app, schedule, driver, race)\n : new JobInOrder(app, schedule, driver, race);\n};\n","import { middleware } from '@aomex/core';\nimport { HelpMiddleware, scriptName } from '@aomex/console';\nimport { chalk } from '@aomex/utility';\n\nexport const runToHelp = (commandName: string): HelpMiddleware =>\n middleware.help(async (ctx, next) => {\n ctx.cli.config({\n all(yargs) {\n yargs.command(chalk.yellow(commandName), 'Star cron jobs');\n },\n detail(yargs) {\n yargs.usage(`${scriptName} ${commandName} [options]`);\n },\n detailCommand: commandName,\n next,\n });\n });\n","import type { ConsoleApp } from '@aomex/console';\nimport cronParser from 'cron-parser';\nimport { sleep } from '@aomex/utility';\nimport { Cache } from '@aomex/core';\nimport { Schedule } from './schedule';\n\nexport class Job {\n public jobAmount: number = 0;\n\n constructor(\n protected readonly app: ConsoleApp,\n protected readonly schedule: Schedule,\n protected readonly driver: Cache,\n protected readonly race: boolean,\n ) {}\n\n async start(): Promise<void> {\n const handle = this.getCronHandle();\n\n while (true) {\n const nextTime = handle.next().getTime();\n const uniqueKey = `cron-job-win-argv:${this.schedule.argv};pattern:${this.schedule.time};time:${nextTime};`;\n await sleep(nextTime - Date.now());\n if (this.schedule.seconds.length) {\n this.emitBySeconds(uniqueKey);\n } else {\n // DO NOT use `await` syntax here due to next loop.\n this.winJob(uniqueKey).then((isWinner) => {\n isWinner && (++this.jobAmount, this.consume());\n });\n }\n if (!handle.hasNext()) break;\n }\n }\n\n emitBySeconds(key: string) {\n const nowSecond = new Date().getSeconds();\n for (const nextSecond of this.schedule.seconds) {\n const delay = nextSecond - nowSecond;\n if (delay >= 0) {\n sleep(delay * 1000).then(async () => {\n const isWinner = await this.winJob(key + `second:${nextSecond};`);\n isWinner && (++this.jobAmount, this.consume());\n });\n }\n }\n }\n\n async winJob(key: string): Promise<boolean> {\n if (this.race) {\n await sleep(this.jobAmount * 5);\n return this.driver.add(key, 1, 100 * 1000);\n }\n return true;\n }\n\n getCronHandle() {\n const now = new Date();\n if (this.schedule.seconds.length) {\n now.setMinutes(now.getMinutes() - 1);\n }\n return cronParser.parseExpression(this.schedule.time, {\n currentDate: now,\n });\n }\n\n async consume() {\n if (this.jobAmount <= 0) return;\n await this.app.run(...this.schedule.argv);\n --this.jobAmount;\n }\n}\n","import { sleep } from '@aomex/utility';\nimport { hostname } from 'node:os';\nimport { Job } from './job';\nimport { Cache } from '@aomex/core';\n\nconst THREE_SECOND = 3 * 1000;\nconst TEN_SECOND = 10 * 1000;\nconst ONE_DAY = 3600 * 24 * 1000;\n\nexport class JobInOrder extends Job {\n protected declare readonly driver: Cache;\n\n queueTimer: NodeJS.Timeout | null = null;\n protected readonly jobId =\n hostname() + Date.now() + Math.random() + ':' + process.pid;\n protected readonly jobKey = `cron-job-queue-argv:${this.schedule.argv};pattern:${this.schedule.time};`;\n\n override async consume() {\n if (this.jobAmount === 0) return;\n await this.ping();\n if (await this.winQueue()) {\n let pingTimer!: NodeJS.Timer;\n try {\n pingTimer = setInterval(() => this.ping(), THREE_SECOND);\n await super.consume();\n } finally {\n clearInterval(pingTimer);\n await this.releaseQueue();\n this.waiting();\n }\n } else {\n this.waiting();\n }\n }\n\n async ping() {\n await this.driver.set(this.getPingKey(this.jobId), 'pong', TEN_SECOND);\n }\n\n getPingKey(jobId: string) {\n return this.jobKey + ':ping:' + jobId;\n }\n\n async winQueue(): Promise<boolean> {\n const win = await this.driver.add(this.jobKey, this.jobId, ONE_DAY);\n if (win) return true;\n {\n const winnerJobId = await this.driver.get<string>(this.jobKey);\n // Job is expired or deleted\n if (winnerJobId === null) return this.winQueue();\n const winnerNotDead = await this.driver.exists(\n this.getPingKey(winnerJobId),\n );\n if (winnerNotDead) return false;\n }\n {\n // Avoid other servers deleting valid key.\n const hasPermissionToReleaseQueue = await this.driver.add(\n this.jobKey + ':delete:',\n this.jobId,\n TEN_SECOND,\n );\n await (hasPermissionToReleaseQueue ? this.releaseQueue() : sleep(100));\n return this.winQueue();\n }\n }\n\n async releaseQueue(): Promise<void> {\n await this.driver.delete(this.jobKey);\n }\n\n waiting() {\n if (this.jobAmount === 0) return;\n this.queueTimer ??= setTimeout(() => {\n this.queueTimer = null;\n this.consume();\n }, 500);\n }\n}\n"],"mappings":";AACA,SAAgB,SAAAA,cAAa;;;ACD7B,SAAS,eAAe;AACxB,SAAS,OAAmB,cAAAC,aAAY,YAAY;AACpD,SAAS,SAAAC,cAAqC;AAC9C,SAAS,OAAO,iBAAiB;AACjC,OAAO,QAAQ,eAAe;;;ACJ9B,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EAEA;AAAA,OACK;;;ACNP,SAAS,yBAAyB;;;ACAlC,SAAS,kBAAkB;AAC3B,OAAO,YAAY;AAuEZ,IAAM,WAAN,MAAe;AAAA,EAKpB,YACqBC,UACnB;AADmB,mBAAAA;AAAA,EAClB;AAAA,EANO;AAAA,EACA;AAAA,EACA;AAAA,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;AAC9C,QAAM,UAAUG,UAAS,WAAWH,MAAK,WAAW;AACpD,SAAO,UACH,IAAI,IAAI,KAAKG,WAAU,QAAQ,IAAI,IACnC,IAAI,WAAW,KAAKA,WAAU,QAAQ,IAAI;AAChD;;;ANiCO,IAAM,OAAO,CAACC,aAAgD;AACnE,QAAM,OACJ,OAAOA,aAAY,WAAW,EAAE,MAAMA,SAAQ,IAAIA;AACpD,SAAOC,OAAM,QAAQ,MAAM,IAAI,IAAI,CAAC,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;AAC9D;","names":["chain","middleware","chalk","options","options","middleware","scriptName","scriptName","middleware","schedule","chalk","middleware","chain","middleware","scriptName","chalk","schedule","sleep","sleep","cron","chain","middleware","schedule","options","chain"]}
1
+ {"version":3,"sources":["../src/middleware/cron.ts","../src/middleware/eject.ts","../src/lib/get-middleware-schedule.ts","../src/middleware/schedule.ts","../src/lib/schedule.ts","../src/middleware/eject-to-help.ts","../src/middleware/run.ts","../src/middleware/run-to-help.ts","../src/lib/job.ts","../src/lib/job-in-order.ts"],"sourcesContent":["import type { ConsoleChain } from '@aomex/console';\nimport { Cache, type PathToFileOptions, chain } from '@aomex/core';\nimport { eject } from './eject';\nimport { run } from './run';\n\nexport interface CronOptions {\n path: PathToFileOptions;\n /**\n * 设置集群服务,任务共享。默认值:`MemoryCache`\n */\n driver?: Cache;\n /**\n * 任务分配模式。默认值:`false`\n * - true: 竞赛,只有一个服务可获得某个任务\n * - false: 每个服务都可以获得某个任务\n */\n race?: boolean;\n /**\n * 任务重叠执行。默认值:`true`\n * - true: 某个任务触发后立即执行。适合允许并发操作的场景\n *\n * - false: 当前被触发的任务,需要等上一次被触发的任务执行完毕后才能执行。场景:\n * 防止数据相互覆盖,防止重复生成数据,防止重复发送通知\n *\n */\n overlap?: boolean;\n}\n\nexport const cron = (options: string | CronOptions): ConsoleChain => {\n const opts: CronOptions =\n typeof options === 'string' ? { path: options } : options;\n return chain.console.mount(run(opts)).mount(eject(opts.path));\n};\n","import { options } from '@aomex/console';\nimport {\n chain,\n chalk,\n Middleware,\n middleware,\n type PathToFileOptions,\n rule,\n} from '@aomex/core';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport path, { dirname } from 'node:path';\nimport { getMiddlewareSchedule } from '../lib/get-middleware-schedule';\nimport { ejectToHelp } from './eject-to-help';\n\nconst exportCron = 'cron:eject';\n\nexport const ejectRule = options(\n {\n output: rule.string().optional().docs({\n description: 'Export to specific file',\n }),\n },\n {\n output: ['o'],\n },\n);\n\nexport const eject = (paths: PathToFileOptions) =>\n chain.console\n .mount(ejectToHelp(exportCron))\n .mount(ejectRule)\n .mount(\n middleware.console<Middleware.Infer<typeof ejectRule>>(\n async (ctx, next) => {\n if (ctx.request.command !== exportCron) {\n Reflect.deleteProperty(ctx, 'options');\n return next();\n }\n\n ctx.response.commandMatched = true;\n\n const schedules = await getMiddlewareSchedule(paths);\n const crons = schedules\n .map((schedule) => schedule.toCrontab())\n .flat();\n\n const { output: outputToFile } = ctx.options;\n if (outputToFile) {\n const file = path.resolve(outputToFile);\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, crons.join('\\n'), {});\n console.log(`Crontab has been created: ${chalk.blue(file)}`);\n } else {\n console.log(crons.join('\\n'));\n }\n },\n ),\n );\n","import { Commander } from '@aomex/commander';\nimport {\n Chain,\n type PathToFileOptions,\n fileToModules,\n pathToFiles,\n} from '@aomex/core';\nimport { ScheduleMiddleware } from '../middleware/schedule';\nimport type { Schedule } from './schedule';\n\nexport const getMiddlewareSchedule = async (paths: PathToFileOptions) => {\n const files = await pathToFiles(paths);\n const commanders = await fileToModules<Commander>(\n files,\n (item) => !!item && item instanceof Commander,\n );\n const schedules: Schedule[] = [];\n for (const commander of commanders) {\n for (const builder of commander['builders']) {\n for (const middleware of Chain.flatten(builder.chain)) {\n if (middleware instanceof ScheduleMiddleware) {\n schedules.push(middleware.getSchedule(builder.commands[0]!));\n }\n }\n }\n }\n return schedules;\n};\n","import { ConsoleMiddleware } from '@aomex/console';\nimport { Schedule, type ScheduleOptions } from '../lib/schedule';\n\nexport class ScheduleMiddleware extends ConsoleMiddleware<object> {\n constructor(protected readonly options: ScheduleOptions) {\n super(async (_, next) => next());\n }\n\n getSchedule(command: string): Schedule {\n return new Schedule({ ...this.options, command });\n }\n}\n\nexport const schedule = (\n options: ScheduleOptions | string,\n): ScheduleMiddleware => {\n return new ScheduleMiddleware(\n typeof options === 'string' ? { time: options } : options,\n );\n};\n","import { scriptName } from '@aomex/console';\nimport parser from 'cron-parser';\nimport type { CronOptions } from '../middleware/cron';\n\ninterface ScheduleTimeObject {\n /**\n * 0-59\n */\n second?: string | number;\n /**\n * 0-59\n */\n minute?: string | number;\n /**\n * 0-23\n */\n hour?: string | number;\n /**\n * 1-31\n */\n dayOfMonth?: string | number;\n /**\n * 0-11\n */\n month?: string | number;\n /**\n * 0-6\n * - 周末: 0\n * - 周一: 1\n */\n dayOfWeek?: string | number;\n}\n\ninterface ScheduleTimeString {\n /**\n 类似linux下cron的时间格式,并支持秒级时间\n ```\n ┌────────────── second (optional)\n │ ┌──────────── minute \n │ │ ┌────────── hour\n │ │ │ ┌──────── day of month\n │ │ │ │ ┌────── month\n │ │ │ │ │ ┌──── day of week\n │ │ │ │ │ │\n `* * * * * *`\n ```\n */\n time: string;\n}\n\ninterface ScheduleBaseOptions {\n /**\n * 执行时附带的参数,使用`options`接收\n *\n * 例子:`['--hello', 'world', '-it', '-o', 'file.txt']`\n */\n args?: (string | number)[];\n /**\n * 任务分配模式。默认值:`cron.race`\n * - true: 竞赛,只有一个服务可获得某个任务\n * - false: 每个服务都可以获得某个任务\n *\n * @see CronOptions.race\n */\n race?: boolean;\n /**\n * 任务重叠执行。默认值:`cron.overlap`\n * - true: 某个任务触发后立即执行。适合允许并发操作的场景\n *\n * - false: 当前被触发的任务,需要等上一次被触发的任务执行完毕后才能执行。场景:\n * 防止数据相互覆盖,防止重复生成数据,防止重复发送通知\n *\n * @see CronOptions.overlap\n */\n overlap?: CronOptions['overlap'];\n}\n\nexport type ScheduleOptions = (ScheduleTimeObject | ScheduleTimeString) &\n ScheduleBaseOptions;\n\nexport class Schedule {\n protected _time?: string;\n protected _seconds?: number[];\n protected _argv?: string[];\n\n constructor(\n protected readonly options: ScheduleOptions & { command: string },\n ) {}\n\n public get overlap(): CronOptions['overlap'] | undefined {\n return this.options.overlap;\n }\n\n public get race(): CronOptions['race'] | undefined {\n return this.options.race;\n }\n\n public get time(): string {\n return (this._time ??= (() => {\n const { options } = this;\n if ('time' in options) {\n const timeList = options.time.split(/\\s+/);\n switch (timeList.length) {\n case 6:\n timeList.shift();\n return timeList.join(' ');\n case 5:\n return timeList.join(' ');\n default:\n throw new Error(`Invalid cron time: \"${options.time}\"`);\n }\n }\n\n return [\n options.minute ?? '*',\n options.hour ?? '*',\n options.dayOfMonth ?? '*',\n options.month ?? '*',\n options.dayOfWeek ?? '*',\n ].join(' ');\n })());\n }\n\n public get argv(): string[] {\n return (this._argv ??= [\n this.options.command,\n ...(this.options.args || []),\n ].map(String));\n }\n\n public get seconds(): number[] {\n return (this._seconds ??= (() => {\n const { options } = this;\n let second: string | undefined;\n\n if ('time' in options) {\n const timeList = options.time.split(/\\s+/);\n if (timeList.length === 6) {\n second = timeList[0]!;\n }\n } else {\n second = options.second?.toString();\n }\n\n if (!second) return [];\n const seconds: number[] = [];\n // second and minute are both 0-59\n const interval = parser.parseExpression(`${second} * * * *`);\n while (true) {\n const nextSecond = interval.next().getMinutes();\n if (seconds.includes(nextSecond)) break;\n seconds.push(nextSecond);\n }\n return seconds.sort((a, b) => a - b);\n })());\n }\n\n public toCrontab(): string[] {\n const script = [this.time];\n const crons: string[][] = [];\n\n for (const second of this.seconds) {\n crons.push(script.concat(`sleep ${second};`));\n }\n\n if (crons.length === 0) {\n crons.push(script);\n }\n\n return crons.map((time) => {\n const argv = this.argv.map((value) =>\n value.includes(' ') ? `\"${value}\"` : value,\n );\n return time.concat(['npx', scriptName, ...argv]).join(' ');\n });\n }\n\n toJSON() {\n return {\n time: this.time,\n seconds: this.seconds,\n argv: this.argv,\n race: this.race,\n overlap: this.overlap,\n };\n }\n}\n","import { HelpMiddleware, scriptName } from '@aomex/console';\nimport { chalk, middleware } from '@aomex/core';\nimport { ejectRule } from './eject';\n\nexport const ejectToHelp = (commandName: string): HelpMiddleware =>\n middleware.help(async (ctx, next) => {\n return ctx.cli.config({\n all(yargs) {\n yargs.command(chalk.yellow(commandName), 'Create cron-compatibly list');\n },\n detail(yargs) {\n yargs.usage(`${scriptName} ${commandName} [options]`);\n ejectRule.toHelp(yargs);\n },\n next,\n detailCommand: commandName,\n });\n });\n","import { middleware, chain, MemoryCache } from '@aomex/core';\nimport { runToHelp } from './run-to-help';\nimport type { CronOptions } from './cron';\nimport { Job } from '../lib/job';\nimport { getMiddlewareSchedule } from '../lib/get-middleware-schedule';\nimport { JobInOrder } from '../lib/job-in-order';\nimport { Schedule } from '../lib/schedule';\nimport { ConsoleApp } from '@aomex/console';\n\nconst runCron = 'cron:run';\n\nexport const run = (cron: CronOptions, forever: boolean = true) =>\n chain.console.mount(runToHelp(runCron)).mount(\n middleware.console(async (ctx, next) => {\n if (ctx.request.command !== runCron) return next();\n ctx.response.commandMatched = true;\n const schedules = await getMiddlewareSchedule(cron.path);\n const promises = schedules.map((schedule) => {\n return createJob(ctx.app, schedule, cron).start();\n });\n // Almost never exit\n if (forever) {\n await Promise.all(promises);\n }\n }),\n );\n\nexport const createJob = (\n app: ConsoleApp,\n schedule: Schedule,\n cron: CronOptions,\n) => {\n const race = schedule.race ?? cron.race ?? false;\n const driver = cron.driver || new MemoryCache();\n const overlap = schedule.overlap ?? cron.overlap ?? true;\n return overlap\n ? new Job(app, schedule, driver, race)\n : new JobInOrder(app, schedule, driver, race);\n};\n","import { chalk, middleware } from '@aomex/core';\nimport { HelpMiddleware, scriptName } from '@aomex/console';\n\nexport const runToHelp = (commandName: string): HelpMiddleware =>\n middleware.help(async (ctx, next) => {\n ctx.cli.config({\n all(yargs) {\n yargs.command(chalk.yellow(commandName), 'Star cron jobs');\n },\n detail(yargs) {\n yargs.usage(`${scriptName} ${commandName} [options]`);\n },\n detailCommand: commandName,\n next,\n });\n });\n","import type { ConsoleApp } from '@aomex/console';\nimport cronParser from 'cron-parser';\nimport { Cache, sleep } from '@aomex/core';\nimport { Schedule } from './schedule';\n\nexport class Job {\n public jobAmount: number = 0;\n\n constructor(\n protected readonly app: ConsoleApp,\n protected readonly schedule: Schedule,\n protected readonly driver: Cache,\n protected readonly race: boolean,\n ) {}\n\n async start(): Promise<void> {\n const handle = this.getCronHandle();\n\n while (true) {\n const nextTime = handle.next().getTime();\n const uniqueKey = `cron-job-win-argv:${this.schedule.argv};pattern:${this.schedule.time};time:${nextTime};`;\n await sleep(nextTime - Date.now());\n if (this.schedule.seconds.length) {\n this.emitBySeconds(uniqueKey);\n } else {\n // 不要使用`await`语法,因为需要立即进入下一个循环\n this.winJob(uniqueKey).then((isWinner) => {\n isWinner && (++this.jobAmount, this.consume());\n });\n }\n if (!handle.hasNext()) break;\n }\n }\n\n emitBySeconds(key: string) {\n const nowSecond = new Date().getSeconds();\n for (const nextSecond of this.schedule.seconds) {\n const delay = nextSecond - nowSecond;\n if (delay >= 0) {\n sleep(delay * 1000).then(async () => {\n const isWinner = await this.winJob(key + `second:${nextSecond};`);\n isWinner && (++this.jobAmount, this.consume());\n });\n }\n }\n }\n\n async winJob(key: string): Promise<boolean> {\n if (this.race) {\n await sleep(this.jobAmount * 5);\n return this.driver.add(key, 1, 100 * 1000);\n }\n return true;\n }\n\n getCronHandle() {\n const now = new Date();\n if (this.schedule.seconds.length) {\n now.setMinutes(now.getMinutes() - 1);\n }\n return cronParser.parseExpression(this.schedule.time, {\n currentDate: now,\n });\n }\n\n async consume() {\n if (this.jobAmount <= 0) return;\n await this.app.run(...this.schedule.argv);\n --this.jobAmount;\n }\n}\n","import { hostname } from 'node:os';\nimport { Job } from './job';\nimport { Cache, sleep } from '@aomex/core';\n\nconst THREE_SECOND = 3 * 1000;\nconst TEN_SECOND = 10 * 1000;\nconst ONE_DAY = 3600 * 24 * 1000;\n\nexport class JobInOrder extends Job {\n protected declare readonly driver: Cache;\n\n queueTimer: NodeJS.Timeout | null = null;\n protected readonly jobId =\n hostname() + Date.now() + Math.random() + ':' + process.pid;\n protected readonly jobKey = `cron-job-queue-argv:${this.schedule.argv};pattern:${this.schedule.time};`;\n\n override async consume() {\n if (this.jobAmount === 0) return;\n await this.ping();\n if (await this.winQueue()) {\n let pingTimer!: NodeJS.Timer;\n try {\n pingTimer = setInterval(() => this.ping(), THREE_SECOND);\n await super.consume();\n } finally {\n clearInterval(pingTimer);\n await this.releaseQueue();\n this.waiting();\n }\n } else {\n this.waiting();\n }\n }\n\n async ping() {\n await this.driver.set(this.getPingKey(this.jobId), 'pong', TEN_SECOND);\n }\n\n getPingKey(jobId: string) {\n return this.jobKey + ':ping:' + jobId;\n }\n\n async winQueue(): Promise<boolean> {\n const win = await this.driver.add(this.jobKey, this.jobId, ONE_DAY);\n if (win) return true;\n {\n const winnerJobId = await this.driver.get<string>(this.jobKey);\n // Job is expired or deleted\n if (winnerJobId === null) return this.winQueue();\n const winnerNotDead = await this.driver.exists(\n this.getPingKey(winnerJobId),\n );\n if (winnerNotDead) return false;\n }\n {\n // Avoid other servers deleting valid key.\n const hasPermissionToReleaseQueue = await this.driver.add(\n this.jobKey + ':delete:',\n this.jobId,\n TEN_SECOND,\n );\n await (hasPermissionToReleaseQueue ? this.releaseQueue() : sleep(100));\n return this.winQueue();\n }\n }\n\n async releaseQueue(): Promise<void> {\n await this.driver.delete(this.jobKey);\n }\n\n waiting() {\n if (this.jobAmount === 0) return;\n this.queueTimer ??= setTimeout(() => {\n this.queueTimer = null;\n this.consume();\n }, 500);\n }\n}\n"],"mappings":";AACA,SAAwC,SAAAA,cAAa;;;ACDrD,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA,SAAAC;AAAA,EAEA,cAAAC;AAAA,EAEA;AAAA,OACK;AACP,SAAS,OAA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sBAAsBF,MAAK,IAAI;AACvD,UAAM,WAAW,UAAU,IAAI,CAACG,cAAa;AAC3C,aAAO,UAAU,IAAI,KAAKA,WAAUH,KAAI,EAAE,MAAM;AAAA,IAClD,CAAC;AAED,QAAI,SAAS;AACX,YAAM,QAAQ,IAAI,QAAQ;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;AAEK,IAAM,YAAY,CACvB,KACAG,WACAH,UACG;AACH,QAAM,OAAOG,UAAS,QAAQH,MAAK,QAAQ;AAC3C,QAAM,SAASA,MAAK,UAAU,IAAI,YAAY;AAC9C,QAAM,UAAUG,UAAS,WAAWH,MAAK,WAAW;AACpD,SAAO,UACH,IAAI,IAAI,KAAKG,WAAU,QAAQ,IAAI,IACnC,IAAI,WAAW,KAAKA,WAAU,QAAQ,IAAI;AAChD;;;ANVO,IAAM,OAAO,CAACC,aAAgD;AACnE,QAAM,OACJ,OAAOA,aAAY,WAAW,EAAE,MAAMA,SAAQ,IAAIA;AACpD,SAAOC,OAAM,QAAQ,MAAM,IAAI,IAAI,CAAC,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;AAC9D;","names":["chain","chalk","middleware","options","options","middleware","scriptName","scriptName","middleware","schedule","chalk","middleware","chain","chalk","middleware","scriptName","schedule","sleep","cron","chain","middleware","schedule","options","chain"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aomex/cron",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",
@@ -26,18 +26,17 @@
26
26
  "homepage": "https://aomex.js.org",
27
27
  "license": "MIT",
28
28
  "peerDependencies": {
29
- "@aomex/console": "^0.0.25",
30
- "@aomex/commander": "^0.0.27",
31
- "@aomex/core": "^0.0.20"
29
+ "@aomex/console": "^0.0.27",
30
+ "@aomex/commander": "^0.0.29",
31
+ "@aomex/core": "^0.0.22"
32
32
  },
33
33
  "dependencies": {
34
- "@aomex/utility": "^0.0.7",
35
34
  "cron-parser": "^4.8.1"
36
35
  },
37
36
  "devDependencies": {
38
- "@aomex/console": "^0.0.25",
39
- "@aomex/commander": "^0.0.27",
40
- "@aomex/core": "^0.0.20",
37
+ "@aomex/console": "^0.0.27",
38
+ "@aomex/commander": "^0.0.29",
39
+ "@aomex/core": "^0.0.22",
41
40
  "strip-ansi": "^7.0.1"
42
41
  },
43
42
  "scripts": {