@kne/fastify-task 3.0.0-alpha.5 → 3.0.0-alpha.6

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/index.js CHANGED
@@ -1,43 +1,12 @@
1
1
  const fp = require('fastify-plugin');
2
2
  const path = require('node:path');
3
+ const { getConfigManager } = require('./libs/utils/config');
3
4
 
4
5
  module.exports = fp(
5
6
  async (fastify, options) => {
6
- options = Object.assign(
7
- {},
8
- {
9
- dbTableNamePrefix: 't_',
10
- prefix: '/api/task',
11
- name: 'task',
12
- limit: 10,
13
- dir: path.resolve(process.cwd(), 'libs', 'tasks'),
14
- /** 任务目录列表,运行时可通过 addDir 动态添加 */
15
- dirs: null,
16
- cronTime: '*/10 * * * *',
17
- scriptName: 'index',
18
- maxPollTimes: 20,
19
- pollInterval: 10000,
20
- /** 任务执行超时时间(毫秒),0 表示不超时,默认 30 分钟 */
21
- taskTimeout: 30 * 60 * 1000,
22
- /** 重试基础延迟(毫秒),实际延迟 = retryBaseDelay * 2^(retryCount-1) */
23
- retryBaseDelay: 5000,
24
- getUserModel: () => {
25
- return fastify.account.models.user;
26
- },
27
- getAuthenticate: () => {
28
- return [fastify.account.authenticate.user, fastify.account.authenticate.admin];
29
- },
30
- task: {}
31
- },
32
- options
33
- );
34
-
35
- // 初始化 dirs:优先使用用户传入的 dirs,否则以 dir 为默认值,保证向后兼容
36
- if (!options.dirs) {
37
- options.dirs = [options.dir];
38
- } else if (!options.dirs.includes(options.dir)) {
39
- options.dirs = [options.dir, ...options.dirs];
40
- }
7
+ // 初始化配置管理器,合并默认配置和用户配置
8
+ const configManager = getConfigManager(options);
9
+ options = configManager.getAll();
41
10
 
42
11
  fastify.register(require('@kne/fastify-statistics'), {
43
12
  dbTableNamePrefix: options.dbTableNamePrefix,
@@ -2,6 +2,7 @@ const fp = require('fastify-plugin');
2
2
 
3
3
  module.exports = fp(async (fastify, options) => {
4
4
  const { services } = fastify[options.name];
5
+
5
6
  // #14: 新增创建任务的 REST 接口
6
7
  fastify.post(
7
8
  `${options.prefix}/create`,