@atri-bot/lib-cron 1.1.0 → 1.1.1
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 +7 -16
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
import * as child_process from 'child_process';
|
|
2
|
-
import * as cron from 'cron';
|
|
3
|
-
import { CronJob } from 'cron';
|
|
4
1
|
import { Logger } from '@huan_kong/logger';
|
|
2
|
+
import { CronJob } from 'cron';
|
|
5
3
|
|
|
6
4
|
interface CronConfig {
|
|
7
5
|
debug: boolean;
|
|
8
6
|
}
|
|
9
7
|
type AddCronOptions = Parameters<typeof CronJob.from>[0] & {
|
|
10
8
|
onTick: () => void | Promise<void>;
|
|
9
|
+
name: string;
|
|
11
10
|
};
|
|
12
11
|
declare class Cron {
|
|
13
12
|
config: CronConfig;
|
|
14
13
|
logger: Logger;
|
|
15
|
-
cronJobs: CronJob
|
|
14
|
+
cronJobs: Record<string, CronJob>;
|
|
16
15
|
constructor(config?: CronConfig);
|
|
17
|
-
add(options: AddCronOptions):
|
|
18
|
-
|
|
19
|
-
args?: readonly string[] | null;
|
|
20
|
-
options?: child_process.SpawnOptions | null;
|
|
21
|
-
} | null, unknown>;
|
|
22
|
-
getCronJobs(): CronJob<null, null>[];
|
|
16
|
+
add(options: AddCronOptions): [1, string] | [0, CronJob];
|
|
17
|
+
getCronJobs(): Record<string, CronJob<null, null>>;
|
|
23
18
|
static instance: Cron;
|
|
24
19
|
static getInstance(): Cron;
|
|
25
|
-
static add(options: AddCronOptions):
|
|
26
|
-
|
|
27
|
-
args?: readonly string[] | null;
|
|
28
|
-
options?: child_process.SpawnOptions | null;
|
|
29
|
-
} | null, unknown>;
|
|
30
|
-
static getCronJobs(): CronJob<null, null>[];
|
|
20
|
+
static add(options: AddCronOptions): [1, string] | [0, CronJob<null, null>];
|
|
21
|
+
static getCronJobs(): Record<string, CronJob<null, null>>;
|
|
31
22
|
}
|
|
32
23
|
|
|
33
24
|
export { type AddCronOptions, Cron, type CronConfig };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Logger as i,LogLevel as
|
|
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};
|