@zenweb/schedule 3.6.0 → 3.7.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 3.7.0
4
+ - paths 支持使用 "./" 开头的相对路径
5
+
6
+ ## 3.6.1
7
+ - null 检查
package/README.md CHANGED
@@ -2,10 +2,27 @@
2
2
 
3
3
  [ZenWeb](https://www.npmjs.com/package/zenweb)
4
4
 
5
- 定时任务
5
+ 基于请求的定时任务,如同定时请求固定接口,可以使用中间件和请求上下文。
6
6
 
7
- ```ts
8
- import { Context } from 'zenweb';
7
+ ## 依赖模块
8
+
9
+ - @zenweb/inject
10
+ - @zenweb/router
11
+
12
+ ## 快速使用
13
+
14
+ ```bash npm2yarn
15
+ npm install @zenweb/schedule
16
+ ```
17
+
18
+ ```ts title="src/index.ts"
19
+ import modSchedule from '@zenweb/schedule';
20
+ // ...
21
+ app.setup(modSchedule());
22
+ // ...
23
+ ```
24
+
25
+ ```ts title="src/schedule/echo.ts"
9
26
  import { schedule } from '@zenweb/schedule';
10
27
 
11
28
  export class EchoScheduler {
@@ -14,10 +31,19 @@ export class EchoScheduler {
14
31
  console.log('task echo');
15
32
  return 'ok';
16
33
  }
17
-
18
- @schedule({ rule: '*/4 * * * * *' })
19
- err(ctx: Context) {
20
- ctx.errrrr();
21
- }
22
34
  }
23
- ```
35
+ ```
36
+
37
+ ## 配置项
38
+
39
+ | 配置项 | 类型 | 默认值 | 功能 |
40
+ | ----- | --- | ----- | ---- |
41
+ | paths | `string[]` | `['./app/schedule']` | 定时任务控制器加载目录
42
+ | patterns | `string` | **/*.{ts,js} | 定时任务控制器文件匹配规则
43
+ | disabled | `boolean` | `false` | 是否禁用定时器,可以通过环境变量 ZENWEB_SCHEDULE_DISABLED=1 控制
44
+
45
+ ## Core 挂载项
46
+
47
+ | 挂载项 | 类型 | 功能 |
48
+ | ----- | --- | ---- |
49
+ | scheduleRegister | ScheduleRegister | ScheduleRegister 实例
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { SetupFunction } from '@zenweb/core';
2
2
  import { schedule, ScheduleRegister } from './register';
3
3
  import { ScheduleOption } from './types';
4
4
  export { ScheduleOption, schedule };
5
- export default function setup(option?: ScheduleOption): SetupFunction;
5
+ export default function setup(opt?: ScheduleOption): SetupFunction;
6
6
  declare module '@zenweb/core' {
7
7
  interface Core {
8
8
  scheduleRegister: ScheduleRegister;
package/dist/index.js CHANGED
@@ -5,11 +5,11 @@ const globby = require("globby");
5
5
  const path = require("path");
6
6
  const register_1 = require("./register");
7
7
  Object.defineProperty(exports, "schedule", { enumerable: true, get: function () { return register_1.schedule; } });
8
- function setup(option) {
9
- option = Object.assign({
10
- paths: [path.join(process.cwd(), 'app', 'schedule')],
8
+ function setup(opt) {
9
+ const option = Object.assign({
10
+ paths: ['./app/schedule'],
11
11
  disabled: process.env.ZENWEB_SCHEDULE_DISABLED === '1',
12
- }, option);
12
+ }, opt);
13
13
  return async function schedule(setup) {
14
14
  setup.assertModuleExists('inject', '@zenweb/inject');
15
15
  setup.assertModuleExists('router', '@zenweb/router');
@@ -17,7 +17,10 @@ function setup(option) {
17
17
  const scheduleRegister = new register_1.ScheduleRegister(setup.core, option);
18
18
  setup.defineCoreProperty('scheduleRegister', { value: scheduleRegister });
19
19
  if (option.paths && option.paths.length) {
20
- for (const d of option.paths) {
20
+ for (let d of option.paths) {
21
+ if (d.startsWith('./')) {
22
+ d = path.join(process.cwd(), d.slice(2));
23
+ }
21
24
  for (const file of await globby(option.patterns || '**/*.{ts,js}', { cwd: d, absolute: true })) {
22
25
  const mod = require(file.slice(0, -3));
23
26
  for (const i of Object.values(mod)) {
@@ -8,7 +8,7 @@ interface ScheduleMethodOption {
8
8
  /**
9
9
  * 定时任务设定
10
10
  */
11
- export declare function schedule(opt: ScheduleMethodOption): (target: Object, propertyKey: string | symbol, descriptor_or_paramtypes?: any[] | PropertyDescriptor) => void;
11
+ export declare function schedule(opt: ScheduleMethodOption): (target: Object, propertyKey: string | symbol, descriptor_or_paramtypes?: any[] | PropertyDescriptor | undefined) => void;
12
12
  export declare class ScheduleRegister {
13
13
  private core;
14
14
  private router;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenweb/schedule",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "Zenweb Schedule module",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "url": "https://github.com/yefei/zenweb-schedule/issues"
35
35
  },
36
36
  "devDependencies": {
37
- "@zenweb/core": "^3.5.0",
37
+ "@zenweb/core": "^3.5.1",
38
38
  "@zenweb/inject": "^3.18.0",
39
39
  "@zenweb/router": "^3.3.0",
40
40
  "cross-env": "^7.0.3",