@zenweb/schedule 3.6.1 → 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,15 +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
  ```
24
36
 
25
- ## Changelog
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 挂载项
26
46
 
27
- ### 3.6.1
28
- - null 检查
47
+ | 挂载项 | 类型 | 功能 |
48
+ | ----- | --- | ---- |
49
+ | scheduleRegister | ScheduleRegister | ScheduleRegister 实例
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ const register_1 = require("./register");
7
7
  Object.defineProperty(exports, "schedule", { enumerable: true, get: function () { return register_1.schedule; } });
8
8
  function setup(opt) {
9
9
  const option = Object.assign({
10
- paths: [path.join(process.cwd(), 'app', 'schedule')],
10
+ paths: ['./app/schedule'],
11
11
  disabled: process.env.ZENWEB_SCHEDULE_DISABLED === '1',
12
12
  }, opt);
13
13
  return async function schedule(setup) {
@@ -17,7 +17,10 @@ function setup(opt) {
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)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenweb/schedule",
3
- "version": "3.6.1",
3
+ "version": "3.7.0",
4
4
  "description": "Zenweb Schedule module",
5
5
  "exports": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",