@aomex/cron 0.0.2 → 0.0.4

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 ADDED
@@ -0,0 +1,30 @@
1
+ # @aomex/cron
2
+
3
+ ## 0.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`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
8
+
9
+ - Updated dependencies [[`b7313d5`](https://github.com/aomex/aomex/commit/b7313d56bdb93cabde8dc5b872a94b590f45b655), [`01f90ab`](https://github.com/aomex/aomex/commit/01f90abec716427b7ccde3ab566067a4ba3293c8), [`c4bb0f4`](https://github.com/aomex/aomex/commit/c4bb0f424e7d2d2f8610583e106cbaef73077278), [`6c6cda2`](https://github.com/aomex/aomex/commit/6c6cda26522176c44761a738f2bc106a1889497b)]:
10
+ - @aomex/file-parser@0.0.4
11
+ - @aomex/console@0.0.7
12
+ - @aomex/console-router@0.0.7
13
+ - @aomex/core@0.0.7
14
+
15
+ ## 0.0.3
16
+
17
+ ### Patch Changes
18
+
19
+ - [`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f) Thanks [@geekact](https://github.com/geekact)! - refactor: rename package helper to utility
20
+
21
+ - [`fa14484`](https://github.com/aomex/aomex/commit/fa14484e35039e4b5ac9fb293648bdf214f7472d) Thanks [@geekact](https://github.com/geekact)! - feat(cron): support cron-like time literal
22
+
23
+ - [`d193c19`](https://github.com/aomex/aomex/commit/d193c198e4951034224587bfe166b7e18eca74bd) Thanks [@geekact](https://github.com/geekact)! - fix(cron): run schedule at wrong time
24
+
25
+ - 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)]:
26
+ - @aomex/file-parser@0.0.3
27
+ - @aomex/console-router@0.0.6
28
+ - @aomex/console@0.0.6
29
+ - @aomex/utility@0.0.4
30
+ - @aomex/core@0.0.6
package/dist/index.d.ts CHANGED
@@ -4,15 +4,13 @@ import { PathToFileOptions } from '@aomex/file-parser';
4
4
  interface CronOptions {
5
5
  paths: PathToFileOptions;
6
6
  /**
7
- * 同一个任务的触发模式:
8
- * - overlap 重叠模式。时间满足就执行,有可能与上一次任务重叠(默认)
9
- * - sequence 顺序模式。当前任务需等待上一次执行结束
7
+ * The way to trigger schedule. Defaults `overlap`
10
8
  */
11
- mode?: 'overlap' | 'sequence';
9
+ mode?: 'overlap' | 'one-by-one';
12
10
  }
13
11
  declare const cron: (options: CronOptions) => ConsoleChain;
14
12
 
15
- interface ScheduleOptions {
13
+ interface ScheduleTimeObject {
16
14
  /**
17
15
  * 0-59
18
16
  */
@@ -35,18 +33,66 @@ interface ScheduleOptions {
35
33
  month?: string | number;
36
34
  /**
37
35
  * 0-6
36
+ * - weekend: 0
37
+ * - monday: 1
38
38
  */
39
39
  dayOfWeek?: string | number;
40
+ }
41
+ interface ScheduleTimeString {
42
+ /**
43
+ Cron-like time, support seconds.
44
+ ```
45
+ ┌────────────── second (optional)
46
+ │ ┌──────────── minute
47
+ │ │ ┌────────── hour
48
+ │ │ │ ┌──────── day of month
49
+ │ │ │ │ ┌────── month
50
+ │ │ │ │ │ ┌──── day of week
51
+ │ │ │ │ │ │
52
+ `* * * * * *`
53
+ ```
54
+ */
55
+ time: string;
56
+ }
57
+ interface ScheduleBaseOptions {
40
58
  args?: (string | number)[];
59
+ /**
60
+ * The way to trigger schedule. If not set, `cron.mode` will be merged.
61
+ * @see CronOptions.mode
62
+ */
63
+ mode?: CronOptions['mode'];
41
64
  }
65
+ type ScheduleOptions = (ScheduleTimeObject | ScheduleTimeString) & ScheduleBaseOptions;
66
+ declare class Schedule {
67
+ protected readonly options: ScheduleOptions & {
68
+ command: string;
69
+ };
70
+ protected _time?: string;
71
+ protected _args?: string[];
72
+ protected _seconds?: number[];
73
+ readonly command: string;
74
+ constructor(options: ScheduleOptions & {
75
+ command: string;
76
+ });
77
+ get mode(): CronOptions['mode'] | undefined;
78
+ get time(): string;
79
+ get args(): string[];
80
+ get seconds(): number[];
81
+ toCrontab(): string[];
82
+ toJSON(): {
83
+ time: string;
84
+ args: string[];
85
+ seconds: number[];
86
+ command: string;
87
+ mode: "overlap" | "one-by-one" | undefined;
88
+ };
89
+ }
90
+
42
91
  declare class ScheduleMiddleware extends ConsoleMiddleware<object> {
43
92
  protected readonly options: ScheduleOptions;
44
93
  constructor(options: ScheduleOptions);
45
- get time(): string[];
46
- get args(): string[];
47
- get seconds(): number[];
48
- toCrontab(command: string): string[];
94
+ getSchedule(command: string): Schedule;
49
95
  }
50
- declare const schedule: (options: ScheduleOptions) => ScheduleMiddleware;
96
+ declare const schedule: (options: ScheduleOptions | string) => ScheduleMiddleware;
51
97
 
52
- export { CronOptions, ScheduleMiddleware, ScheduleOptions, cron, schedule };
98
+ export { CronOptions, ScheduleMiddleware, cron, schedule };
package/dist/index.js CHANGED
@@ -1,92 +1,174 @@
1
- // src/cron.ts
1
+ // src/middleware/cron.ts
2
2
  import { chain as chain3 } from "@aomex/core";
3
3
 
4
- // src/output.ts
4
+ // src/middleware/output.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";
8
+ import { mkdir, writeFile } from "node:fs/promises";
9
+ import path, { dirname } from "node:path";
10
+
11
+ // src/lib/get-middleware-schedule.ts
6
12
  import { Commander } from "@aomex/console-router";
7
- import { Chain, chain, middleware as middleware2, rule } from "@aomex/core";
13
+ import { Chain } from "@aomex/core";
8
14
  import {
9
15
  fileToModules,
10
16
  pathToFiles
11
17
  } from "@aomex/file-parser";
12
- import { chalk } from "@aomex/helper";
13
- import { mkdir, writeFile } from "node:fs/promises";
14
- import path, { dirname } from "node:path";
15
18
 
16
- // src/output-to-help.ts
17
- import { scriptName } from "@aomex/console";
18
- import { middleware } from "@aomex/core";
19
- var outputToHelp = (commandName) => middleware.help(async (ctx, next) => {
20
- const { status, yargs } = ctx.cli;
21
- switch (status) {
22
- case "show-all":
23
- yargs.command(commandName, "Create cron-compatibly list");
24
- return next();
25
- case "show-detail":
26
- if (ctx.request.command !== commandName)
27
- return next();
28
- yargs.usage(`${scriptName} ${commandName} [options]`);
29
- outputRule.toHelp(yargs);
30
- ctx.response.commandMatched = true;
31
- return;
32
- default:
33
- const _ = status;
34
- assert(_);
35
- }
36
- });
19
+ // src/middleware/schedule.ts
20
+ import { ConsoleMiddleware } from "@aomex/console";
37
21
 
38
- // src/schedule.ts
39
- import { ConsoleMiddleware, scriptName as scriptName2 } from "@aomex/console";
22
+ // src/lib/schedule.ts
23
+ import { scriptName } from "@aomex/console";
40
24
  import parser from "cron-parser";
41
- var ScheduleMiddleware = class extends ConsoleMiddleware {
25
+ var Schedule = class {
42
26
  constructor(options2) {
43
- super(async (_, next) => next());
44
27
  this.options = options2;
28
+ this.command = options2.command;
29
+ }
30
+ _time;
31
+ _args;
32
+ _seconds;
33
+ command;
34
+ get mode() {
35
+ return this.options.mode;
45
36
  }
46
37
  get time() {
47
- const { options: opts } = this;
48
- return [
49
- opts.minute ?? "*",
50
- opts.hour ?? "*",
51
- opts.dayOfMonth ?? "*",
52
- opts.month ?? "*",
53
- opts.dayOfWeek ?? "*"
54
- ].map(String);
38
+ return this._time ??= (() => {
39
+ const { options: options2 } = this;
40
+ if ("time" in options2) {
41
+ const timeList = options2.time.split(/\s+/);
42
+ switch (timeList.length) {
43
+ case 6:
44
+ timeList.shift();
45
+ return timeList.join(" ");
46
+ case 5:
47
+ return timeList.join(" ");
48
+ default:
49
+ throw new Error(`Invalid cron time: "${options2.time}"`);
50
+ }
51
+ }
52
+ return [
53
+ options2.minute ?? "*",
54
+ options2.hour ?? "*",
55
+ options2.dayOfMonth ?? "*",
56
+ options2.month ?? "*",
57
+ options2.dayOfWeek ?? "*"
58
+ ].join(" ");
59
+ })();
55
60
  }
56
61
  get args() {
57
- return (this.options.args || []).map(String);
62
+ return this._args ??= (this.options.args || []).map(String);
58
63
  }
59
64
  get seconds() {
60
- if (!this.options.second)
61
- return [];
62
- const seconds = [];
63
- const interval = parser.parseExpression(`${this.options.second} * * * *`);
64
- while (true) {
65
- const second = interval.next().getMinutes();
66
- if (seconds.includes(second))
67
- break;
68
- seconds.push(second);
69
- }
70
- return seconds.sort((a, b) => a - b);
65
+ return this._seconds ??= (() => {
66
+ const { options: options2 } = this;
67
+ let second;
68
+ if ("time" in options2) {
69
+ const timeList = options2.time.split(/\s+/);
70
+ if (timeList.length === 6) {
71
+ second = timeList[0];
72
+ }
73
+ } else {
74
+ second = options2.second?.toString();
75
+ }
76
+ if (!second)
77
+ return [];
78
+ const seconds = [];
79
+ const interval = parser.parseExpression(`${second} * * * *`);
80
+ while (true) {
81
+ const nextSecond = interval.next().getMinutes();
82
+ if (seconds.includes(nextSecond))
83
+ break;
84
+ seconds.push(nextSecond);
85
+ }
86
+ return seconds.sort((a, b) => a - b);
87
+ })();
71
88
  }
72
- toCrontab(command) {
73
- const script = this.time;
74
- const crons = [script];
89
+ toCrontab() {
90
+ const script = [this.time];
91
+ const crons = [];
75
92
  for (const second of this.seconds) {
76
93
  crons.push(script.concat(`sleep ${second};`));
77
94
  }
78
- return crons.map((item) => {
95
+ if (crons.length === 0) {
96
+ crons.push(script);
97
+ }
98
+ return crons.map((time) => {
79
99
  const args = this.args.map(
80
100
  (value) => value.includes(" ") ? `"${value}"` : value
81
101
  );
82
- return item.concat(["npx", scriptName2, command, ...args]).join(" ");
102
+ return time.concat(["npx", scriptName, this.command, ...args]).join(" ");
83
103
  });
84
104
  }
105
+ toJSON() {
106
+ return {
107
+ time: this.time,
108
+ args: this.args,
109
+ seconds: this.seconds,
110
+ command: this.command,
111
+ mode: this.mode
112
+ };
113
+ }
85
114
  };
86
- var schedule = (options2) => new ScheduleMiddleware(options2);
87
115
 
88
- // src/output.ts
89
- var exportSchedule = "schedule:export";
116
+ // src/middleware/schedule.ts
117
+ var ScheduleMiddleware = class extends ConsoleMiddleware {
118
+ constructor(options2) {
119
+ super(async (_, next) => next());
120
+ this.options = options2;
121
+ }
122
+ getSchedule(command) {
123
+ return new Schedule({ ...this.options, command });
124
+ }
125
+ };
126
+ var schedule = (options2) => {
127
+ return new ScheduleMiddleware(
128
+ typeof options2 === "string" ? { time: options2 } : options2
129
+ );
130
+ };
131
+
132
+ // src/lib/get-middleware-schedule.ts
133
+ var getMiddlewareSchedule = async (paths) => {
134
+ const files = await pathToFiles(paths);
135
+ const commanders = await fileToModules(
136
+ files,
137
+ (item) => !!item && item instanceof Commander
138
+ );
139
+ const schedules = [];
140
+ for (const commander of commanders) {
141
+ for (const builder of Commander.getBuilders(commander)) {
142
+ for (const middleware5 of Chain.flatten(builder.chain)) {
143
+ if (middleware5 instanceof ScheduleMiddleware) {
144
+ schedules.push(middleware5.getSchedule(builder.commands[0]));
145
+ }
146
+ }
147
+ }
148
+ }
149
+ return schedules;
150
+ };
151
+
152
+ // src/middleware/output-to-help.ts
153
+ import { scriptName as scriptName2 } from "@aomex/console";
154
+ import { middleware } from "@aomex/core";
155
+ import { chalk } from "@aomex/utility";
156
+ var outputToHelp = (commandName) => middleware.help(async (ctx, next) => {
157
+ return ctx.cli.config({
158
+ all(yargs) {
159
+ yargs.command(chalk.yellow(commandName), "Create cron-compatibly list");
160
+ },
161
+ detail(yargs) {
162
+ yargs.usage(`${scriptName2} ${commandName} [options]`);
163
+ outputRule.toHelp(yargs);
164
+ },
165
+ next,
166
+ detailCommand: commandName
167
+ });
168
+ });
169
+
170
+ // src/middleware/output.ts
171
+ var exportCron = "cron:export";
90
172
  var outputRule = options(
91
173
  {
92
174
  output: rule.string().optional().docs({
@@ -97,35 +179,22 @@ var outputRule = options(
97
179
  output: ["o"]
98
180
  }
99
181
  );
100
- var output = (paths) => chain.console.mount(outputToHelp(exportSchedule)).mount(outputRule).mount(
182
+ var output = (paths) => chain.console.mount(outputToHelp(exportCron)).mount(outputRule).mount(
101
183
  middleware2.console(
102
184
  async (ctx, next) => {
103
- if (ctx.request.command !== exportSchedule) {
185
+ if (ctx.request.command !== exportCron) {
104
186
  Reflect.deleteProperty(ctx, "options");
105
187
  return next();
106
188
  }
107
189
  ctx.response.commandMatched = true;
108
- const files = await pathToFiles(paths);
109
- const commanders = await fileToModules(
110
- files,
111
- (item) => !!item && item instanceof Commander
112
- );
113
- const crons = [];
114
- for (const commander of commanders) {
115
- for (const builder of Commander.getBuilders(commander)) {
116
- for (const middleware5 of Chain.flatten(builder.chain)) {
117
- if (middleware5 instanceof ScheduleMiddleware) {
118
- crons.push(...middleware5.toCrontab(builder.commands[0]));
119
- }
120
- }
121
- }
122
- }
190
+ const schedules = await getMiddlewareSchedule(paths);
191
+ const crons = schedules.map((schedule2) => schedule2.toCrontab()).flat();
123
192
  const { output: outputToFile } = ctx.options;
124
193
  if (outputToFile) {
125
194
  const file = path.resolve(outputToFile);
126
195
  await mkdir(dirname(file), { recursive: true });
127
196
  await writeFile(file, crons.join("\n"), {});
128
- console.log(`Crontab has been created: ${chalk.blue(file)}`);
197
+ console.log(`Crontab has been created: ${chalk2.blue(file)}`);
129
198
  } else {
130
199
  console.log(crons.join("\n"));
131
200
  }
@@ -133,161 +202,112 @@ var output = (paths) => chain.console.mount(outputToHelp(exportSchedule)).mount(
133
202
  )
134
203
  );
135
204
 
136
- // src/run.ts
137
- import { Commander as Commander2 } from "@aomex/console-router";
138
- import { middleware as middleware4, Chain as Chain2, chain as chain2 } from "@aomex/core";
139
- import {
140
- pathToFiles as pathToFiles2,
141
- fileToModules as fileToModules2
142
- } from "@aomex/file-parser";
205
+ // src/middleware/run.ts
206
+ import { middleware as middleware4, chain as chain2 } from "@aomex/core";
143
207
 
144
- // src/run-to-help.ts
208
+ // src/middleware/run-to-help.ts
145
209
  import { middleware as middleware3 } from "@aomex/core";
146
210
  import { scriptName as scriptName3 } from "@aomex/console";
211
+ import { chalk as chalk3 } from "@aomex/utility";
147
212
  var runToHelp = (commandName) => middleware3.help(async (ctx, next) => {
148
- const { status, yargs } = ctx.cli;
149
- switch (status) {
150
- case "show-all":
151
- yargs.command(commandName, "Star cron");
152
- return next();
153
- case "show-detail":
154
- if (ctx.request.command !== commandName)
155
- return next();
156
- yargs.usage(`${scriptName3} ${commandName} [options]
157
- Schedule list:
158
- `);
159
- ctx.response.commandMatched = true;
160
- return;
161
- default:
162
- const _ = status;
163
- assert(_);
164
- }
213
+ ctx.cli.config({
214
+ all(yargs) {
215
+ yargs.command(chalk3.yellow(commandName), "Star cron jobs");
216
+ },
217
+ detail(yargs) {
218
+ yargs.usage(`${scriptName3} ${commandName} [options]`);
219
+ },
220
+ detailCommand: commandName,
221
+ next
222
+ });
165
223
  });
166
224
 
167
- // src/cron-job.ts
168
- import { fileURLToPath } from "node:url";
169
- import { isMainThread, Worker } from "node:worker_threads";
225
+ // src/lib/job.ts
170
226
  import cronParser from "cron-parser";
171
- import { sleep } from "@aomex/helper";
172
- var CronJob = class {
173
- constructor(app, schedule2, mode = "overlap") {
227
+ import { sleep } from "@aomex/utility";
228
+ var Job = class {
229
+ constructor(app, time, seconds, argv, mode) {
174
230
  this.app = app;
175
- this.schedule = schedule2;
231
+ this.time = time;
232
+ this.seconds = seconds;
233
+ this.argv = argv;
176
234
  this.mode = mode;
177
235
  }
178
236
  queue = 0;
237
+ executing = false;
179
238
  async start() {
180
- if (this.mode === "sequence")
181
- this.sequenceLoop();
182
- const {
183
- schedule: { seconds }
184
- } = this;
185
- const cronExp = this.getCronExp();
239
+ const handle = this.getCronHandle();
186
240
  while (true) {
187
- const nextTime = cronExp.next();
188
- await sleep(nextTime.getTime() - Date.now());
189
- if (seconds.length) {
190
- const nowSecond = nextTime.getSeconds();
191
- seconds.forEach(async (expectedSecond) => {
192
- const delay = expectedSecond - nowSecond;
241
+ await sleep(handle.next().getTime() - Date.now());
242
+ if (this.seconds.length) {
243
+ const nowSecond = (/* @__PURE__ */ new Date()).getSeconds();
244
+ this.seconds.forEach(async (nextSecond) => {
245
+ const delay = nextSecond - nowSecond;
193
246
  if (delay >= 0) {
194
247
  await sleep(delay * 1e3);
195
- this.executeOrQueue();
248
+ this.emit();
196
249
  }
197
250
  });
198
251
  } else {
199
- this.executeOrQueue();
252
+ this.emit();
200
253
  }
201
254
  }
202
255
  }
203
- getCronExp() {
204
- const {
205
- schedule: { seconds, time }
206
- } = this;
256
+ getCronHandle() {
207
257
  const now = /* @__PURE__ */ new Date();
208
- if (seconds.length) {
258
+ if (this.seconds.length) {
209
259
  now.setMinutes(now.getMinutes() - 1);
210
260
  }
211
- return cronParser.parseExpression(time, {
261
+ return cronParser.parseExpression(this.time, {
212
262
  currentDate: now
213
263
  });
214
264
  }
215
- executeOrQueue() {
216
- if (this.mode === "sequence") {
265
+ emit() {
266
+ if (this.mode === "one-by-one") {
217
267
  ++this.queue;
268
+ this.executeWithoutOverlapping();
218
269
  } else {
219
270
  this.execute();
220
271
  }
221
272
  }
222
- async execute() {
223
- if (isMainThread) {
224
- await this.createWorker();
225
- } else {
226
- try {
227
- await this.app.run(this.schedule.command, ...this.schedule.args);
228
- } catch {
229
- }
230
- }
231
- }
232
- createWorker() {
233
- const worker = new Worker(fileURLToPath(import.meta.url), {
234
- stdout: true
273
+ execute() {
274
+ return this.app.run(...this.argv).catch(() => {
235
275
  });
236
- return new Promise((resolve) => {
237
- worker.on("exit", () => {
238
- resolve(void 0);
239
- });
276
+ }
277
+ executeWithoutOverlapping() {
278
+ if (this.executing || this.queue === 0)
279
+ return;
280
+ --this.queue;
281
+ this.executing = true;
282
+ this.execute().finally(() => {
283
+ this.executing = false;
284
+ this.executeWithoutOverlapping();
240
285
  });
241
286
  }
242
- sequenceLoop = () => {
243
- if (this.queue > 0) {
244
- --this.queue;
245
- this.execute().finally(this.sequenceLoop);
246
- } else {
247
- setTimeout(this.sequenceLoop, 300);
248
- }
249
- };
250
287
  };
251
288
 
252
- // src/run.ts
253
- var runSchedule = "schedule:run";
254
- var run = ({ paths, mode }) => chain2.console.mount(runToHelp(runSchedule)).mount(
289
+ // src/middleware/run.ts
290
+ var runCron = "cron:start";
291
+ var run = ({ paths, mode }) => chain2.console.mount(runToHelp(runCron)).mount(
255
292
  middleware4.console(async (ctx, next) => {
256
- if (ctx.request.command !== runSchedule)
293
+ if (ctx.request.command !== runCron)
257
294
  return next();
258
295
  ctx.response.commandMatched = true;
259
- const schedules = await getSchedules(paths);
296
+ const schedules = await getMiddlewareSchedule(paths);
260
297
  schedules.forEach(async (schedule2) => {
261
- const job = new CronJob(ctx.app, schedule2, mode);
298
+ const job = new Job(
299
+ ctx.app,
300
+ schedule2.time,
301
+ schedule2.seconds,
302
+ [schedule2.command, ...schedule2.args],
303
+ schedule2.mode ?? mode
304
+ );
262
305
  await job.start();
263
306
  });
264
307
  })
265
308
  );
266
- var getSchedules = async (paths) => {
267
- const files = await pathToFiles2(paths);
268
- const commanders = await fileToModules2(
269
- files,
270
- (item) => !!item && item instanceof Commander2
271
- );
272
- const tasks = [];
273
- for (const commander of commanders) {
274
- for (const builder of Commander2.getBuilders(commander)) {
275
- for (const middleware5 of Chain2.flatten(builder.chain)) {
276
- if (middleware5 instanceof ScheduleMiddleware) {
277
- tasks.push({
278
- time: middleware5.time.join(" "),
279
- seconds: middleware5.seconds,
280
- command: builder.commands[0],
281
- args: middleware5.args
282
- });
283
- }
284
- }
285
- }
286
- }
287
- return tasks;
288
- };
289
309
 
290
- // src/cron.ts
310
+ // src/middleware/cron.ts
291
311
  var cron = (options2) => chain3.console.mount(run(options2)).mount(output(options2.paths));
292
312
  export {
293
313
  ScheduleMiddleware,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cron.ts","../src/output.ts","../src/output-to-help.ts","../src/schedule.ts","../src/run.ts","../src/run-to-help.ts","../src/cron-job.ts"],"sourcesContent":["import type { ConsoleChain } from '@aomex/console';\nimport { chain } from '@aomex/core';\nimport type { PathToFileOptions } from '@aomex/file-parser';\nimport { output } from './output';\nimport { run } from './run';\n\nexport interface CronOptions {\n paths: PathToFileOptions;\n /**\n * 同一个任务的触发模式:\n * - overlap 重叠模式。时间满足就执行,有可能与上一次任务重叠(默认)\n * - sequence 顺序模式。当前任务需等待上一次执行结束\n */\n mode?: 'overlap' | 'sequence';\n}\n\nexport const cron = (options: CronOptions): ConsoleChain =>\n chain.console.mount(run(options)).mount(output(options.paths));\n","import { options } from '@aomex/console';\nimport { Commander } from '@aomex/console-router';\nimport { Chain, chain, Middleware, middleware, rule } from '@aomex/core';\nimport {\n fileToModules,\n PathToFileOptions,\n pathToFiles,\n} from '@aomex/file-parser';\nimport { chalk } from '@aomex/helper';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport path, { dirname } from 'node:path';\nimport { outputToHelp } from './output-to-help';\nimport { ScheduleMiddleware } from './schedule';\n\nconst exportSchedule = 'schedule:export';\n\nexport const outputRule = 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 output = (paths: PathToFileOptions) =>\n chain.console\n .mount(outputToHelp(exportSchedule))\n .mount(outputRule)\n .mount(\n middleware.console<Middleware.Infer<typeof outputRule>>(\n async (ctx, next) => {\n if (ctx.request.command !== exportSchedule) {\n Reflect.deleteProperty(ctx, 'options');\n return next();\n }\n\n ctx.response.commandMatched = true;\n const files = await pathToFiles(paths);\n const commanders = await fileToModules<Commander>(\n files,\n (item) => !!item && item instanceof Commander,\n );\n\n const crons: string[] = [];\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 crons.push(...middleware.toCrontab(builder.commands[0]!));\n }\n }\n }\n }\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 { HelpMiddleware, scriptName } from '@aomex/console';\nimport { middleware } from '@aomex/core';\nimport { outputRule } from './output';\n\nexport const outputToHelp = (commandName: string): HelpMiddleware =>\n middleware.help(async (ctx, next) => {\n const { status, yargs } = ctx.cli;\n switch (status) {\n case 'show-all':\n yargs.command(commandName, 'Create cron-compatibly list');\n return next();\n case 'show-detail':\n if (ctx.request.command !== commandName) return next();\n yargs.usage(`${scriptName} ${commandName} [options]`);\n outputRule.toHelp(yargs);\n ctx.response.commandMatched = true;\n return;\n default:\n const _: never = status;\n assert(_);\n }\n });\n","import { ConsoleMiddleware, scriptName } from '@aomex/console';\nimport parser from 'cron-parser';\n\nexport interface ScheduleOptions {\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 */\n dayOfWeek?: string | number;\n args?: (string | number)[];\n}\n\nexport class ScheduleMiddleware extends ConsoleMiddleware<object> {\n constructor(protected readonly options: ScheduleOptions) {\n super(async (_, next) => next());\n }\n\n public get time(): string[] {\n const { options: opts } = this;\n return [\n opts.minute ?? '*',\n opts.hour ?? '*',\n opts.dayOfMonth ?? '*',\n opts.month ?? '*',\n opts.dayOfWeek ?? '*',\n ].map(String);\n }\n\n public get args() {\n return (this.options.args || []).map(String);\n }\n\n public get seconds(): number[] {\n if (!this.options.second) return [];\n const seconds: number[] = [];\n // second and minute are both 0-59\n const interval = parser.parseExpression(`${this.options.second} * * * *`);\n while (true) {\n const second = interval.next().getMinutes();\n if (seconds.includes(second)) break;\n seconds.push(second);\n }\n return seconds.sort((a, b) => a - b);\n }\n\n public toCrontab(command: string): string[] {\n const script = this.time;\n const crons: string[][] = [script];\n for (const second of this.seconds) {\n crons.push(script.concat(`sleep ${second};`));\n }\n return crons.map((item) => {\n const args = this.args.map((value) =>\n value.includes(' ') ? `\"${value}\"` : value,\n );\n return item.concat(['npx', scriptName, command, ...args]).join(' ');\n });\n }\n}\n\nexport const schedule = (options: ScheduleOptions): ScheduleMiddleware =>\n new ScheduleMiddleware(options);\n","import { Commander } from '@aomex/console-router';\nimport { middleware, Chain, chain } from '@aomex/core';\nimport {\n pathToFiles,\n fileToModules,\n PathToFileOptions,\n} from '@aomex/file-parser';\nimport { ScheduleMiddleware } from './schedule';\nimport { runToHelp } from './run-to-help';\nimport type { CronOptions } from './cron';\nimport { CronJob, CronJobOptions } from './cron-job';\n\nconst runSchedule = 'schedule:run';\n\nexport const run = ({ paths, mode }: CronOptions) =>\n chain.console.mount(runToHelp(runSchedule)).mount(\n middleware.console(async (ctx, next) => {\n if (ctx.request.command !== runSchedule) return next();\n ctx.response.commandMatched = true;\n const schedules = await getSchedules(paths);\n schedules.forEach(async (schedule) => {\n const job = new CronJob(ctx.app, schedule, mode);\n await job.start();\n });\n }),\n );\n\nexport const getSchedules = async (\n paths: PathToFileOptions,\n): Promise<CronJobOptions[]> => {\n const files = await pathToFiles(paths);\n const commanders = await fileToModules<Commander>(\n files,\n (item) => !!item && item instanceof Commander,\n );\n const tasks: CronJobOptions[] = [];\n\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 tasks.push({\n time: middleware.time.join(' '),\n seconds: middleware.seconds,\n command: builder.commands[0]!,\n args: middleware.args,\n });\n }\n }\n }\n }\n\n return tasks;\n};\n","import { middleware } from '@aomex/core';\nimport { HelpMiddleware, scriptName } from '@aomex/console';\n\nexport const runToHelp = (commandName: string): HelpMiddleware =>\n middleware.help(async (ctx, next) => {\n const { status, yargs } = ctx.cli;\n switch (status) {\n case 'show-all':\n yargs.command(commandName, 'Star cron');\n return next();\n case 'show-detail':\n if (ctx.request.command !== commandName) return next();\n yargs.usage(`${scriptName} ${commandName} [options]\\nSchedule list:\\n`);\n ctx.response.commandMatched = true;\n return;\n default:\n const _: never = status;\n assert(_);\n }\n });\n","import type { ConsoleApp } from '@aomex/console';\nimport { fileURLToPath } from 'node:url';\nimport { isMainThread, Worker } from 'node:worker_threads';\nimport cronParser from 'cron-parser';\nimport type { CronOptions } from './cron';\nimport { sleep } from '@aomex/helper';\n\nexport interface CronJobOptions {\n time: string;\n seconds: number[];\n args: string[];\n command: string;\n}\n\nexport class CronJob {\n public queue: number = 0;\n\n constructor(\n protected readonly app: ConsoleApp,\n protected readonly schedule: CronJobOptions,\n protected readonly mode: CronOptions['mode'] = 'overlap',\n ) {}\n\n async start(): Promise<void> {\n if (this.mode === 'sequence') this.sequenceLoop();\n\n const {\n schedule: { seconds },\n } = this;\n const cronExp = this.getCronExp();\n\n while (true) {\n const nextTime = cronExp.next();\n await sleep(nextTime.getTime() - Date.now());\n if (seconds.length) {\n const nowSecond = nextTime.getSeconds();\n seconds.forEach(async (expectedSecond) => {\n const delay = expectedSecond - nowSecond;\n if (delay >= 0) {\n await sleep(delay * 1000);\n this.executeOrQueue();\n }\n });\n } else {\n this.executeOrQueue();\n }\n }\n }\n\n getCronExp() {\n const {\n schedule: { seconds, time },\n } = this;\n const now = new Date();\n if (seconds.length) {\n now.setMinutes(now.getMinutes() - 1);\n }\n return cronParser.parseExpression(time, {\n currentDate: now,\n });\n }\n\n executeOrQueue() {\n if (this.mode === 'sequence') {\n ++this.queue;\n } else {\n this.execute();\n }\n }\n\n async execute() {\n if (isMainThread) {\n await this.createWorker();\n } else {\n try {\n await this.app.run(this.schedule.command, ...this.schedule.args);\n } catch {}\n }\n }\n\n createWorker(): Promise<void> {\n const worker = new Worker(fileURLToPath(import.meta.url), {\n stdout: true,\n });\n return new Promise((resolve) => {\n worker.on('exit', () => {\n resolve(void 0);\n });\n });\n }\n\n sequenceLoop = () => {\n if (this.queue > 0) {\n --this.queue;\n this.execute().finally(this.sequenceLoop);\n } else {\n setTimeout(this.sequenceLoop, 300);\n }\n };\n}\n"],"mappings":";AACA,SAAS,SAAAA,cAAa;;;ACDtB,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,OAAO,OAAmB,cAAAC,aAAY,YAAY;AAC3D;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,aAAa;AACtB,SAAS,OAAO,iBAAiB;AACjC,OAAO,QAAQ,eAAe;;;ACV9B,SAAyB,kBAAkB;AAC3C,SAAS,kBAAkB;AAGpB,IAAM,eAAe,CAAC,gBAC3B,WAAW,KAAK,OAAO,KAAK,SAAS;AACnC,QAAM,EAAE,QAAQ,MAAM,IAAI,IAAI;AAC9B,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,YAAM,QAAQ,aAAa,6BAA6B;AACxD,aAAO,KAAK;AAAA,IACd,KAAK;AACH,UAAI,IAAI,QAAQ,YAAY;AAAa,eAAO,KAAK;AACrD,YAAM,MAAM,GAAG,cAAc,uBAAuB;AACpD,iBAAW,OAAO,KAAK;AACvB,UAAI,SAAS,iBAAiB;AAC9B;AAAA,IACF;AACE,YAAM,IAAW;AACjB,aAAO,CAAC;AAAA,EACZ;AACF,CAAC;;;ACrBH,SAAS,mBAAmB,cAAAC,mBAAkB;AAC9C,OAAO,YAAY;AA8BZ,IAAM,qBAAN,cAAiC,kBAA0B;AAAA,EAChE,YAA+BC,UAA0B;AACvD,UAAM,OAAO,GAAG,SAAS,KAAK,CAAC;AADF,mBAAAA;AAAA,EAE/B;AAAA,EAEA,IAAW,OAAiB;AAC1B,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,KAAK,MAChCC,OAAM,QAAQ,MAAM,UAAU,WAAW,CAAC,EAAE;AAAA,EAC1CC,YAAW,QAAQ,OAAO,KAAK,SAAS;AACtC,QAAI,IAAI,QAAQ,YAAY;AAAa,aAAO,KAAK;AACrD,QAAI,SAAS,iBAAiB;AAC9B,UAAM,YAAY,MAAM,aAAa,KAAK;AAC1C,cAAU,QAAQ,OAAOC,cAAa;AACpC,YAAM,MAAM,IAAI,QAAQ,IAAI,KAAKA,WAAU,IAAI;AAC/C,YAAM,IAAI,MAAM;AAAA,IAClB,CAAC;AAAA,EACH,CAAC;AACH;AAEK,IAAM,eAAe,OAC1B,UAC8B;AAC9B,QAAM,QAAQ,MAAMC,aAAY,KAAK;AACrC,QAAM,aAAa,MAAMC;AAAA,IACvB;AAAA,IACA,CAAC,SAAS,CAAC,CAAC,QAAQ,gBAAgBC;AAAA,EACtC;AACA,QAAM,QAA0B,CAAC;AAEjC,aAAW,aAAa,YAAY;AAClC,eAAW,WAAWA,WAAU,YAAY,SAAS,GAAG;AACtD,iBAAWJ,eAAcK,OAAM,QAAQ,QAAQ,KAAK,GAAG;AACrD,YAAIL,uBAAsB,oBAAoB;AAC5C,gBAAM,KAAK;AAAA,YACT,MAAMA,YAAW,KAAK,KAAK,GAAG;AAAA,YAC9B,SAASA,YAAW;AAAA,YACpB,SAAS,QAAQ,SAAS,CAAC;AAAA,YAC3B,MAAMA,YAAW;AAAA,UACnB,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;;;AJrCO,IAAM,OAAO,CAACM,aACnBC,OAAM,QAAQ,MAAM,IAAID,QAAO,CAAC,EAAE,MAAM,OAAOA,SAAQ,KAAK,CAAC;","names":["chain","middleware","scriptName","options","middleware","Commander","middleware","Chain","chain","pathToFiles","fileToModules","middleware","scriptName","schedule","chain","middleware","schedule","pathToFiles","fileToModules","Commander","Chain","options","chain"]}
1
+ {"version":3,"sources":["../src/middleware/cron.ts","../src/middleware/output.ts","../src/lib/get-middleware-schedule.ts","../src/middleware/schedule.ts","../src/lib/schedule.ts","../src/middleware/output-to-help.ts","../src/middleware/run.ts","../src/middleware/run-to-help.ts","../src/lib/job.ts"],"sourcesContent":["import type { ConsoleChain } from '@aomex/console';\nimport { chain } from '@aomex/core';\nimport type { PathToFileOptions } from '@aomex/file-parser';\nimport { output } from './output';\nimport { run } from './run';\n\nexport interface CronOptions {\n paths: PathToFileOptions;\n /**\n * The way to trigger schedule. Defaults `overlap`\n */\n mode?: 'overlap' | 'one-by-one';\n}\n\nexport const cron = (options: CronOptions): ConsoleChain =>\n chain.console.mount(run(options)).mount(output(options.paths));\n","import { options } from '@aomex/console';\nimport { chain, Middleware, middleware, rule } from '@aomex/core';\nimport type { PathToFileOptions } from '@aomex/file-parser';\nimport { chalk } from '@aomex/utility';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport path, { dirname } from 'node:path';\nimport { getMiddlewareSchedule } from '../lib/get-middleware-schedule';\nimport { outputToHelp } from './output-to-help';\n\nconst exportCron = 'cron:export';\n\nexport const outputRule = 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 output = (paths: PathToFileOptions) =>\n chain.console\n .mount(outputToHelp(exportCron))\n .mount(outputRule)\n .mount(\n middleware.console<Middleware.Infer<typeof outputRule>>(\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/console-router';\nimport { Chain } from '@aomex/core';\nimport {\n fileToModules,\n PathToFileOptions,\n pathToFiles,\n} from '@aomex/file-parser';\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, 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 args?: (string | number)[];\n /**\n * The way to trigger schedule. If not set, `cron.mode` will be merged.\n * @see CronOptions.mode\n */\n mode?: CronOptions['mode'];\n}\n\nexport type ScheduleOptions = (ScheduleTimeObject | ScheduleTimeString) &\n ScheduleBaseOptions;\n\nexport class Schedule {\n protected _time?: string;\n protected _args?: string[];\n protected _seconds?: number[];\n\n public readonly command: string;\n\n constructor(\n protected readonly options: ScheduleOptions & { command: string },\n ) {\n this.command = options.command;\n }\n\n public get mode(): CronOptions['mode'] | undefined {\n return this.options.mode;\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 args(): string[] {\n return (this._args ??= (this.options.args || []).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 args = this.args.map((value) =>\n value.includes(' ') ? `\"${value}\"` : value,\n );\n return time.concat(['npx', scriptName, this.command, ...args]).join(' ');\n });\n }\n\n toJSON() {\n return {\n time: this.time,\n args: this.args,\n seconds: this.seconds,\n command: this.command,\n mode: this.mode,\n };\n }\n}\n","import { HelpMiddleware, scriptName } from '@aomex/console';\nimport { middleware } from '@aomex/core';\nimport { chalk } from '@aomex/utility';\nimport { outputRule } from './output';\n\nexport const outputToHelp = (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 outputRule.toHelp(yargs);\n },\n next,\n detailCommand: commandName,\n });\n });\n","import { middleware, chain } 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';\n\nconst runCron = 'cron:start';\n\nexport const run = ({ paths, mode }: CronOptions) =>\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\n const schedules = await getMiddlewareSchedule(paths);\n schedules.forEach(async (schedule) => {\n const job = new Job(\n ctx.app,\n schedule.time,\n schedule.seconds,\n [schedule.command, ...schedule.args],\n schedule.mode ?? mode,\n );\n await job.start();\n });\n }),\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 type { CronOptions } from '../middleware/cron';\n\nexport class Job {\n public queue: number = 0;\n protected executing: boolean = false;\n\n constructor(\n protected readonly app: ConsoleApp,\n protected readonly time: string,\n protected readonly seconds: number[],\n protected readonly argv: string[],\n protected readonly mode?: CronOptions['mode'],\n ) {}\n\n async start(): Promise<void> {\n const handle = this.getCronHandle();\n\n while (true) {\n await sleep(handle.next().getTime() - Date.now());\n if (this.seconds.length) {\n const nowSecond = new Date().getSeconds();\n this.seconds.forEach(async (nextSecond) => {\n const delay = nextSecond - nowSecond;\n if (delay >= 0) {\n await sleep(delay * 1000);\n this.emit();\n }\n });\n } else {\n this.emit();\n }\n }\n }\n\n getCronHandle() {\n const now = new Date();\n if (this.seconds.length) {\n now.setMinutes(now.getMinutes() - 1);\n }\n return cronParser.parseExpression(this.time, {\n currentDate: now,\n });\n }\n\n emit() {\n if (this.mode === 'one-by-one') {\n ++this.queue;\n this.executeWithoutOverlapping();\n } else {\n this.execute();\n }\n }\n\n execute() {\n return this.app.run(...this.argv).catch(() => {});\n }\n\n executeWithoutOverlapping() {\n if (this.executing || this.queue === 0) return;\n --this.queue;\n this.executing = true;\n this.execute().finally(() => {\n this.executing = false;\n this.executeWithoutOverlapping();\n });\n }\n}\n"],"mappings":";AACA,SAAS,SAAAA,cAAa;;;ACDtB,SAAS,eAAe;AACxB,SAAS,OAAmB,cAAAC,aAAY,YAAY;AAEpD,SAAS,SAAAC,cAAa;AACtB,SAAS,OAAO,iBAAiB;AACjC,OAAO,QAAQ,eAAe;;;ACL9B,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EAEA;AAAA,OACK;;;ACNP,SAAS,yBAAyB;;;ACAlC,SAAS,kBAAkB;AAC3B,OAAO,YAAY;AA6DZ,IAAM,WAAN,MAAe;AAAA,EAOpB,YACqBC,UACnB;AADmB,mBAAAA;AAEnB,SAAK,UAAUA,SAAQ;AAAA,EACzB;AAAA,EAVU;AAAA,EACA;AAAA,EACA;AAAA,E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AAA,EACtCC,YAAW,QAAQ,OAAO,KAAK,SAAS;AACtC,QAAI,IAAI,QAAQ,YAAY;AAAS,aAAO,KAAK;AACjD,QAAI,SAAS,iBAAiB;AAE9B,UAAM,YAAY,MAAM,sBAAsB,KAAK;AACnD,cAAU,QAAQ,OAAOC,cAAa;AACpC,YAAM,MAAM,IAAI;AAAA,QACd,IAAI;AAAA,QACJA,UAAS;AAAA,QACTA,UAAS;AAAA,QACT,CAACA,UAAS,SAAS,GAAGA,UAAS,IAAI;AAAA,QACnCA,UAAS,QAAQ;AAAA,MACnB;AACA,YAAM,IAAI,MAAM;AAAA,IAClB,CAAC;AAAA,EACH,CAAC;AACH;;;ANZK,IAAM,OAAO,CAACC,aACnBC,OAAM,QAAQ,MAAM,IAAID,QAAO,CAAC,EAAE,MAAM,OAAOA,SAAQ,KAAK,CAAC;","names":["chain","middleware","chalk","options","options","middleware","scriptName","scriptName","middleware","schedule","chalk","middleware","chain","middleware","scriptName","chalk","chain","middleware","schedule","options","chain"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aomex/cron",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",
@@ -26,19 +26,20 @@
26
26
  "homepage": "https://aomex.js.org",
27
27
  "license": "MIT",
28
28
  "peerDependencies": {
29
- "@aomex/console": "^0.0.5",
30
- "@aomex/console-router": "^0.0.5",
31
- "@aomex/core": "^0.0.5"
29
+ "@aomex/console": "^0.0.7",
30
+ "@aomex/console-router": "^0.0.7",
31
+ "@aomex/core": "^0.0.7"
32
32
  },
33
33
  "dependencies": {
34
- "@aomex/file-parser": "^0.0.2",
35
- "@aomex/helper": "^0.0.3",
36
- "cron-parser": "^4.7.1"
34
+ "@aomex/file-parser": "^0.0.4",
35
+ "@aomex/utility": "^0.0.4",
36
+ "cron-parser": "^4.8.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@aomex/console": "^0.0.5",
40
- "@aomex/console-router": "^0.0.5",
41
- "@aomex/core": "^0.0.5"
39
+ "@aomex/console": "^0.0.7",
40
+ "@aomex/console-router": "^0.0.7",
41
+ "@aomex/core": "^0.0.7",
42
+ "strip-ansi": "^7.0.1"
42
43
  },
43
44
  "scripts": {}
44
45
  }