@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 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: boolean;
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?: CronConfig);
16
- add(options: AddCronOptions): [1, string] | [0, CronJob];
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 { type AddCronOptions, Cron, type CronConfig };
21
+ export { Cron };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{Logger as i,LogLevel as r}from"@huan_kong/logger";import{CronJob as s}from"cron";import g from"process";var e=class t{config;logger;cronJobs={};constructor(n={debug:g.argv.includes("--debug")}){this.config=n,this.logger=new i({title:"Cron",level:this.config.debug?r.DEBUG:r.INFO})}add(n){if(this.cronJobs[n.name])return[1,`Cron job with name ${n.name} already exists`];"timeZone"in n||(n.timeZone="Asia/Shanghai"),n.onTick=()=>{this.logger.DEBUG("\u5B9A\u65F6\u4EFB\u52A1\u89E6\u53D1!"),n.onTick()};let o=s.from(n);return this.cronJobs[n.name]=o,[0,o]}getCronJobs(){return this.cronJobs}static instance;static getInstance(){return this.instance||(this.instance=new t),this.instance}static add(n){return this.getInstance().add(n)}static getCronJobs(){return this.getInstance().getCronJobs()}};export{e as Cron};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atri-bot/lib-cron",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "cron lib for atri framework",
5
5
  "author": "huan_kong",
6
6
  "license": "MIT",