@atri-bot/lib-cron 1.1.1 → 1.1.3
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 +8 -11
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import { Logger } from '@huan_kong/logger';
|
|
1
|
+
import { LogLevel, Logger } from '@huan_kong/logger';
|
|
2
2
|
import { CronJob } from 'cron';
|
|
3
3
|
|
|
4
4
|
interface CronConfig {
|
|
5
|
-
debug
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
logLevel?: LogLevel;
|
|
6
7
|
}
|
|
7
8
|
type AddCronOptions = Parameters<typeof CronJob.from>[0] & {
|
|
8
9
|
onTick: () => void | Promise<void>;
|
|
9
10
|
name: string;
|
|
10
11
|
};
|
|
12
|
+
|
|
11
13
|
declare class Cron {
|
|
12
14
|
config: CronConfig;
|
|
13
15
|
logger: Logger;
|
|
14
|
-
cronJobs: Record<string, CronJob
|
|
15
|
-
constructor(config
|
|
16
|
-
add(options: AddCronOptions):
|
|
17
|
-
getCronJobs(): Record<string, CronJob<null, null>>;
|
|
18
|
-
static instance: Cron;
|
|
19
|
-
static getInstance(): Cron;
|
|
20
|
-
static add(options: AddCronOptions): [1, string] | [0, CronJob<null, null>];
|
|
21
|
-
static getCronJobs(): Record<string, CronJob<null, null>>;
|
|
16
|
+
cronJobs: Record<string, CronJob<null, null>>;
|
|
17
|
+
constructor(config: CronConfig);
|
|
18
|
+
add(options: AddCronOptions): CronJob;
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
export {
|
|
21
|
+
export { Cron };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Logger as
|
|
1
|
+
import{Logger as s,LogLevel as g}from"@huan_kong/logger";import{CronJob as c}from"cron";var r=class extends Error{constructor(o){super(o),this.name="CronJobNameExistsError"}};var m={},e=class{config;logger;cronJobs=m;constructor(o){this.config=o,this.logger=new s({title:"Cron",level:o.logLevel??(o.debug?g.DEBUG:void 0)})}add(o){if(this.cronJobs[o.name])throw new r;"timeZone"in o||(o.timeZone="Asia/Shanghai"),o.onTick=(i=>async()=>{this.logger.DEBUG("\u5B9A\u65F6\u4EFB\u52A1\u89E6\u53D1!"),await i()})(o.onTick);let n=c.from(o);return this.cronJobs[o.name]=n,n}};export{e as Cron};
|