@atri-bot/lib-cron 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +9 -21
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as cron from 'cron';
|
|
1
|
+
import { LogLevel, Logger } from '@huan_kong/logger';
|
|
3
2
|
import { CronJob } from 'cron';
|
|
4
|
-
import { Logger } from '@huan_kong/logger';
|
|
5
3
|
|
|
6
4
|
interface CronConfig {
|
|
7
|
-
debug
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
logLevel?: LogLevel;
|
|
8
7
|
}
|
|
9
8
|
type AddCronOptions = Parameters<typeof CronJob.from>[0] & {
|
|
10
9
|
onTick: () => void | Promise<void>;
|
|
10
|
+
name: string;
|
|
11
11
|
};
|
|
12
|
+
|
|
12
13
|
declare class Cron {
|
|
13
14
|
config: CronConfig;
|
|
14
15
|
logger: Logger;
|
|
15
|
-
cronJobs: CronJob
|
|
16
|
-
constructor(config
|
|
17
|
-
add(options: AddCronOptions): CronJob
|
|
18
|
-
command: string;
|
|
19
|
-
args?: readonly string[] | null;
|
|
20
|
-
options?: child_process.SpawnOptions | null;
|
|
21
|
-
} | null, unknown>;
|
|
22
|
-
getCronJobs(): CronJob<null, null>[];
|
|
23
|
-
static instance: Cron;
|
|
24
|
-
static getInstance(): Cron;
|
|
25
|
-
static add(options: AddCronOptions): CronJob<string | cron.CronOnCompleteCallback | {
|
|
26
|
-
command: string;
|
|
27
|
-
args?: readonly string[] | null;
|
|
28
|
-
options?: child_process.SpawnOptions | null;
|
|
29
|
-
} | null, unknown>;
|
|
30
|
-
static getCronJobs(): CronJob<null, null>[];
|
|
16
|
+
cronJobs: Record<string, CronJob<null, null>>;
|
|
17
|
+
constructor(config: CronConfig);
|
|
18
|
+
add(options: AddCronOptions): CronJob;
|
|
31
19
|
}
|
|
32
20
|
|
|
33
|
-
export {
|
|
21
|
+
export { Cron };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Logger as i,LogLevel as
|
|
1
|
+
import{Logger as i,LogLevel as s}from"@huan_kong/logger";import{CronJob as g}from"cron";var r=class extends Error{constructor(o){super(o),this.name="CronJobNameExistsError"}};var c={},e=class{config;logger;cronJobs=c;constructor(o){this.config=o,this.logger=new i({title:"Cron",level:o.logLevel??(o.debug?s.DEBUG:void 0)})}add(o){if(this.cronJobs[o.name])throw new r;"timeZone"in o||(o.timeZone="Asia/Shanghai"),o.onTick=async()=>{this.logger.DEBUG("\u5B9A\u65F6\u4EFB\u52A1\u89E6\u53D1!"),await o.onTick()};let n=g.from(o);return this.cronJobs[o.name]=n,n}};export{e as Cron};
|