@kne/fastify-task 0.1.2 → 0.1.3
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/libs/services/main.js +27 -5
- package/package.json +1 -1
package/libs/services/main.js
CHANGED
|
@@ -130,11 +130,33 @@ module.exports = fp(async (fastify, options) => {
|
|
|
130
130
|
return task;
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
-
const cancel = async ({ id }) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
const cancel = async ({ id, targetId, targetType }) => {
|
|
134
|
+
if (targetId && targetType) {
|
|
135
|
+
return await models.task.update(
|
|
136
|
+
{
|
|
137
|
+
status: 'canceled'
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
where: {
|
|
141
|
+
targetId,
|
|
142
|
+
targetType,
|
|
143
|
+
status: {
|
|
144
|
+
[Op.in]: ['pending', 'running']
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
if (id) {
|
|
151
|
+
const task = await detail({ id });
|
|
152
|
+
if (!['pending', 'running'].includes(task.type)) {
|
|
153
|
+
throw new Error('任务状态不允许取消');
|
|
154
|
+
}
|
|
155
|
+
return await task.update({
|
|
156
|
+
status: 'canceled'
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
throw new Error('参数错误');
|
|
138
160
|
};
|
|
139
161
|
|
|
140
162
|
const complete = async ({ id, userId, output, ...props }) => {
|