@atri-bot/lib-cron 1.1.4 → 1.1.5
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.mts +21 -0
- package/dist/index.mjs +1 -0
- package/package.json +8 -9
- package/dist/index.d.ts +0 -22
- package/dist/index.js +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as _atri_bot_core0 from "@atri-bot/core";
|
|
2
|
+
import { CronJob } from "cron";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
interface CronConfig {
|
|
6
|
+
timeZone?: string;
|
|
7
|
+
}
|
|
8
|
+
type AddCronOptions = Parameters<typeof CronJob.from>[0] & {
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
11
|
+
declare function CronPlugin(config: CronConfig): _atri_bot_core0.definePluginReturnType<CronConfig, {
|
|
12
|
+
pluginName: string;
|
|
13
|
+
config: CronConfig;
|
|
14
|
+
install(): void;
|
|
15
|
+
uninstall(): void;
|
|
16
|
+
getCronJobs(): Record<string, CronJob<null, null>>;
|
|
17
|
+
add(options: AddCronOptions): [false, string] | [true, CronJob];
|
|
18
|
+
remove(name: string): void;
|
|
19
|
+
}>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { AddCronOptions, CronConfig, CronPlugin };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{definePlugin as e}from"@atri-bot/core";import{CronJob as t}from"cron";const n={};function r(r){return e({pluginName:`Cron`,config:r,install(){},uninstall(){},getCronJobs(){return n},add(e){if(n[e.name])return[!1,`name already exists`];`timeZone`in e||(e.timeZone=this.config.timeZone??`Asia/Shanghai`);let r=t.from(e);return n[e.name]=r,[!0,r]},remove(e){let t=n[e];t&&(t.stop(),delete n[e])}})}export{r as CronPlugin};
|
package/package.json
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atri-bot/lib-cron",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.1.5",
|
|
4
5
|
"description": "cron lib for atri framework",
|
|
5
6
|
"author": "huan_kong",
|
|
6
7
|
"license": "MIT",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
8
|
+
"main": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
10
10
|
"files": [
|
|
11
11
|
"./dist/**/*"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "
|
|
15
|
-
"clean": "rimraf dist",
|
|
14
|
+
"build": "tsdown",
|
|
16
15
|
"lint": "eslint",
|
|
17
|
-
"lint:fix": "eslint --fix",
|
|
18
16
|
"type-check": "tsc --noEmit -p tsconfig.json --composite false"
|
|
19
17
|
},
|
|
20
18
|
"dependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"cron": "^4.
|
|
19
|
+
"@atri-bot/core": "^2.0.0-beta.3",
|
|
20
|
+
"cron": "^4.4.0",
|
|
21
|
+
"cron-validate": "^1.5.3"
|
|
23
22
|
}
|
|
24
23
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { LogLevel, Logger } from '@huan_kong/logger';
|
|
2
|
-
import { CronJob } from 'cron';
|
|
3
|
-
|
|
4
|
-
interface CronConfig {
|
|
5
|
-
debug?: boolean;
|
|
6
|
-
logLevel?: LogLevel;
|
|
7
|
-
}
|
|
8
|
-
type AddCronOptions = Parameters<typeof CronJob.from>[0] & {
|
|
9
|
-
onTick: () => void | Promise<void>;
|
|
10
|
-
name: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
declare class Cron {
|
|
14
|
-
config: CronConfig;
|
|
15
|
-
logger: Logger;
|
|
16
|
-
cronJobs: Record<string, CronJob<null, null>>;
|
|
17
|
-
constructor(config: CronConfig);
|
|
18
|
-
add(options: AddCronOptions): CronJob;
|
|
19
|
-
remove(name: string): void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { Cron };
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Logger as i,LogLevel as g}from"@huan_kong/logger";import{CronJob as c}from"cron";var e=class extends Error{constructor(o){super(o),this.name="CronJobNameExistsError"}};var l={},n=class{config;logger;cronJobs=l;constructor(o){this.config=o,this.logger=new i({title:"Cron",level:o.logLevel??(o.debug?g.DEBUG:void 0)})}add(o){if(this.cronJobs[o.name])throw new e;"timeZone"in o||(o.timeZone="Asia/Shanghai"),o.onTick=(s=>async()=>{this.logger.DEBUG("\u5B9A\u65F6\u4EFB\u52A1\u89E6\u53D1!"),await s()})(o.onTick);let r=c.from(o);return this.cronJobs[o.name]=r,r}remove(o){let r=this.cronJobs[o];r?(r.stop(),delete this.cronJobs[o],this.logger.DEBUG(`\u5B9A\u65F6\u4EFB\u52A1 ${o} \u5DF2\u79FB\u9664`)):this.logger.WARN(`\u5B9A\u65F6\u4EFB\u52A1 ${o} \u4E0D\u5B58\u5728\uFF0C\u65E0\u6CD5\u79FB\u9664`)}};export{n as Cron};
|