@kne/fastify-task 3.0.0-alpha.8 → 3.0.0-alpha.9
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
CHANGED
|
@@ -504,7 +504,6 @@ const signature = generateSignature({
|
|
|
504
504
|
| type | string | 是 | - | 任务类型,必须已在主项目或 `append` 中声明 |
|
|
505
505
|
| targetId | string | 是 | - | 目标对象ID |
|
|
506
506
|
| targetType | string | 是 | - | 目标对象类型 |
|
|
507
|
-
| targetName | string | 否 | - | 目标对象名称 |
|
|
508
507
|
| input | object | 否 | - | 输入数据 |
|
|
509
508
|
| runnerType | string | 否 | - | 执行者类型:`manual` / `system` |
|
|
510
509
|
| delay | number | 否 | `0` | 延迟执行秒数 |
|
|
@@ -533,7 +532,6 @@ const signature = generateSignature({
|
|
|
533
532
|
| currentPage | number | 否 | `1` | 当前页码 |
|
|
534
533
|
| filter.id | string | 否 | - | 任务ID |
|
|
535
534
|
| filter.targetId | string | 否 | - | 目标对象ID |
|
|
536
|
-
| filter.targetName | string | 否 | - | 目标名称(模糊匹配 `input.name`) |
|
|
537
535
|
| filter.type | string | 否 | - | 任务类型 |
|
|
538
536
|
| filter.status | string | 否 | - | 任务状态 |
|
|
539
537
|
| filter.runnerType | string | 否 | - | 执行者类型 |
|
|
@@ -710,7 +708,7 @@ SSE 实时推送任务统计数据,需 `statistics` 权限。
|
|
|
710
708
|
|
|
711
709
|
| 方法签名 | 说明 |
|
|
712
710
|
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
|
|
713
|
-
| `services.create({ userId, input, type, targetId, targetType,
|
|
711
|
+
| `services.create({ userId, input, type, targetId, targetType, runnerType, delay, scriptName, priority, parentTaskId, maxRetries, timeout, context, options })` | 创建任务,返回 Task 实例 |
|
|
714
712
|
| `services.detail({ id })` | 获取任务详情,返回 Task 实例 |
|
|
715
713
|
| `services.list({ filter, perPage, currentPage, sort })` | 获取任务列表,返回 `{ pageData, totalCount }` |
|
|
716
714
|
| `services.complete({ id, userId, status, output, error })` | 手动完成任务 |
|
|
@@ -727,7 +725,6 @@ SSE 实时推送任务统计数据,需 `statistics` 权限。
|
|
|
727
725
|
| type | string | 是 | - | 任务类型 |
|
|
728
726
|
| targetId | string | 是 | - | 目标对象ID |
|
|
729
727
|
| targetType | string | 是 | - | 目标对象类型 |
|
|
730
|
-
| targetName | string | 否 | - | 目标对象名称 |
|
|
731
728
|
| runnerType | string | 否 | - | 执行者类型 |
|
|
732
729
|
| delay | number | 否 | `0` | 延迟执行秒数 |
|
|
733
730
|
| scriptName | string | 否 | - | 脚本名称 |
|
|
@@ -825,7 +822,6 @@ SSE 实时推送任务统计数据,需 `statistics` 权限。
|
|
|
825
822
|
| scriptName | string | 任务脚本名称 |
|
|
826
823
|
| targetId | string | 任务目标对象ID |
|
|
827
824
|
| targetType | string | 任务目标对象类型 |
|
|
828
|
-
| targetName | string | 任务目标对象名称 |
|
|
829
825
|
| runnerType | string | 执行者类型:`manual` / `system`,默认 `manual` |
|
|
830
826
|
| priority | number | 任务优先级,数值越大越优先,默认 0 |
|
|
831
827
|
| parentTaskId | string | 父任务ID,用于任务依赖 |
|
package/libs/controllers/main.js
CHANGED
|
@@ -323,7 +323,7 @@ const createContext = (fastify, options) => {
|
|
|
323
323
|
return true;
|
|
324
324
|
};
|
|
325
325
|
|
|
326
|
-
const create = async ({ userId, input, type, targetId, targetType,
|
|
326
|
+
const create = async ({ userId, input, type, targetId, targetType, runnerType, delay = 0, scriptName, priority = 0, parentTaskId, maxRetries = 0, timeout = 60 * 60 * 1000, context, options: currentOptions }) => {
|
|
327
327
|
if (typeof delay !== 'number' || delay < 0) {
|
|
328
328
|
throw new Error('delay 必须为非负数');
|
|
329
329
|
}
|
|
@@ -344,7 +344,6 @@ const createContext = (fastify, options) => {
|
|
|
344
344
|
type: declaration.type,
|
|
345
345
|
targetId,
|
|
346
346
|
targetType,
|
|
347
|
-
targetName,
|
|
348
347
|
runnerType,
|
|
349
348
|
priority,
|
|
350
349
|
parentTaskId,
|
|
@@ -485,7 +484,6 @@ const createContext = (fastify, options) => {
|
|
|
485
484
|
type: nextDeclaration.type,
|
|
486
485
|
targetId: task.id,
|
|
487
486
|
targetType: 'task',
|
|
488
|
-
targetName: task.input?.name || task.targetName,
|
|
489
487
|
runnerType: task.runnerType,
|
|
490
488
|
input,
|
|
491
489
|
context: cloneJsonValue(task.context || {}),
|
package/libs/models/task.js
CHANGED
|
@@ -18,10 +18,6 @@ module.exports = ({ DataTypes, definePrimaryType, options }) => {
|
|
|
18
18
|
comment: '任务目标对象类型',
|
|
19
19
|
allowNull: false
|
|
20
20
|
},
|
|
21
|
-
targetName: {
|
|
22
|
-
type: DataTypes.STRING,
|
|
23
|
-
comment: '任务目标对象名称'
|
|
24
|
-
},
|
|
25
21
|
runnerType: {
|
|
26
22
|
type: DataTypes.ENUM('manual', 'system'),
|
|
27
23
|
comment: '任务执行者类型: manual为手动执行, system为系统自动执行',
|
|
@@ -25,10 +25,8 @@ const parseRange = (range = '7d', tz) => {
|
|
|
25
25
|
// 写入数据全使用服务器时间,查询用客户端时间
|
|
26
26
|
// 使用客户端时区计算"现在"和"起始时间",确保日期边界对齐客户端视角
|
|
27
27
|
const now = tz ? dayjs().tz(tz) : dayjs();
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const startTime = startUnit
|
|
31
|
-
? now.subtract(config.value, startUnit).startOf(startUnit)
|
|
28
|
+
const startTime = config.unit === 'day'
|
|
29
|
+
? now.subtract(config.value, config.unit).startOf('day')
|
|
32
30
|
: now.subtract(config.value, config.unit);
|
|
33
31
|
return { startTime: startTime.toDate(), endTime: now.toDate(), label: config.label, range };
|
|
34
32
|
};
|
package/libs/services/task.js
CHANGED
|
@@ -4,7 +4,7 @@ const getTaskServiceContext = require('../helpers/task-service-context');
|
|
|
4
4
|
module.exports = fp(async (fastify, options) => {
|
|
5
5
|
const context = getTaskServiceContext(fastify, options);
|
|
6
6
|
const { models, Op } = context;
|
|
7
|
-
const SORTABLE_FIELDS = new Set(['id', 'targetId', 'targetType', '
|
|
7
|
+
const SORTABLE_FIELDS = new Set(['id', 'targetId', 'targetType', 'type', 'status', 'runnerType', 'priority', 'createdAt', 'updatedAt', 'startTime', 'startedAt', 'completedAt']);
|
|
8
8
|
|
|
9
9
|
const cancel = async ({ id, targetId, targetType, type }) => {
|
|
10
10
|
if (!id && !(targetId && targetType && type)) {
|
|
@@ -151,12 +151,6 @@ module.exports = fp(async (fastify, options) => {
|
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
153
|
|
|
154
|
-
if (filter && filter.targetName) {
|
|
155
|
-
whereQuery['input.name'] = {
|
|
156
|
-
[Op.like]: `%${filter.targetName}%`
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
154
|
if (filter && filter.createdAt) {
|
|
161
155
|
whereQuery.createdAt = getTimeQuery(filter.createdAt);
|
|
162
156
|
}
|