@kne/fastify-task 1.0.4 → 1.0.5
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 +23 -8
- package/package.json +1 -1
package/libs/services/main.js
CHANGED
|
@@ -246,15 +246,30 @@ module.exports = fp(async (fastify, options) => {
|
|
|
246
246
|
|
|
247
247
|
const complete = async ({ id, userId, output, ...props }) => {
|
|
248
248
|
const task = await detail({ id });
|
|
249
|
+
if (!task) {
|
|
250
|
+
throw new Error('任务不存在');
|
|
251
|
+
}
|
|
249
252
|
if (props.status === 'success') {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
253
|
+
try {
|
|
254
|
+
await options.task[task.type]({ task, result: output });
|
|
255
|
+
await task.update({
|
|
256
|
+
status: 'success',
|
|
257
|
+
output,
|
|
258
|
+
progress: 100,
|
|
259
|
+
completedAt: new Date(),
|
|
260
|
+
completedUserId: userId
|
|
261
|
+
});
|
|
262
|
+
} catch (e) {
|
|
263
|
+
await task.update(
|
|
264
|
+
Object.assign({}, props, {
|
|
265
|
+
status: 'failed',
|
|
266
|
+
output,
|
|
267
|
+
error: (e.stack || '').replaceAll(process.cwd(), '/server'),
|
|
268
|
+
completedAt: new Date()
|
|
269
|
+
})
|
|
270
|
+
);
|
|
271
|
+
throw e;
|
|
272
|
+
}
|
|
258
273
|
} else {
|
|
259
274
|
await task.update(
|
|
260
275
|
Object.assign({}, props, {
|