@atri-bot/lib-cron 1.1.0

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # atri-lib-cron
2
+
3
+ 定时任务支持库
@@ -0,0 +1,33 @@
1
+ import * as child_process from 'child_process';
2
+ import * as cron from 'cron';
3
+ import { CronJob } from 'cron';
4
+ import { Logger } from '@huan_kong/logger';
5
+
6
+ interface CronConfig {
7
+ debug: boolean;
8
+ }
9
+ type AddCronOptions = Parameters<typeof CronJob.from>[0] & {
10
+ onTick: () => void | Promise<void>;
11
+ };
12
+ declare class Cron {
13
+ config: CronConfig;
14
+ logger: Logger;
15
+ cronJobs: CronJob[];
16
+ constructor(config?: CronConfig);
17
+ add(options: AddCronOptions): CronJob<string | cron.CronOnCompleteCallback | {
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>[];
31
+ }
32
+
33
+ export { type AddCronOptions, Cron, type CronConfig };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{Logger as i,LogLevel as t}from"@huan_kong/logger";import{CronJob as s}from"cron";import g from"process";var e=class r{config;logger;cronJobs=[];constructor(o={debug:g.argv.includes("--debug")}){this.config=o,this.logger=new i({title:"Cron",level:this.config.debug?t.DEBUG:t.INFO})}add(o){"timeZone"in o||(o.timeZone="Asia/Shanghai"),o.onTick=()=>{this.logger.DEBUG("\u5B9A\u65F6\u4EFB\u52A1\u89E6\u53D1!"),o.onTick()};let n=s.from(o);return this.cronJobs.push(n),n}getCronJobs(){return this.cronJobs}static instance;static getInstance(){return this.instance||(this.instance=new r),this.instance}static add(o){return this.getInstance().add(o)}static getCronJobs(){return this.getInstance().getCronJobs()}};export{e as Cron};
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@atri-bot/lib-cron",
3
+ "version": "1.1.0",
4
+ "description": "cron lib for atri framework",
5
+ "author": "huan_kong",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "files": [
11
+ "./dist/**/*"
12
+ ],
13
+ "scripts": {
14
+ "build": "pnpm run type-check && pnpm run lint && tsup",
15
+ "clean": "rimraf dist",
16
+ "lint": "eslint",
17
+ "lint:fix": "eslint --fix",
18
+ "type-check": "tsc --noEmit -p tsconfig.json --composite false"
19
+ },
20
+ "dependencies": {
21
+ "@huan_kong/logger": "^1.0.6",
22
+ "cron": "^4.3.3"
23
+ }
24
+ }