@kne/fastify-task 0.1.10 → 0.1.12
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 +10 -4
- package/package.json +1 -1
package/libs/services/main.js
CHANGED
|
@@ -42,6 +42,12 @@ module.exports = fp(async (fastify, options) => {
|
|
|
42
42
|
}
|
|
43
43
|
return await require(taskModulePath)(fastify, options, {
|
|
44
44
|
...props,
|
|
45
|
+
updateProgress: async progress => {
|
|
46
|
+
props.task &&
|
|
47
|
+
(await props.task.update({
|
|
48
|
+
progress: progress
|
|
49
|
+
}));
|
|
50
|
+
},
|
|
45
51
|
polling: async (callback, currentOptions) => {
|
|
46
52
|
let pollCount = 0;
|
|
47
53
|
const maxPollTimes = currentOptions?.maxPollTimes || options.maxPollTimes;
|
|
@@ -51,12 +57,12 @@ module.exports = fp(async (fastify, options) => {
|
|
|
51
57
|
pollCount++;
|
|
52
58
|
if (pollCount > maxPollTimes) {
|
|
53
59
|
clearInterval(timer);
|
|
54
|
-
reject(`轮询超时(${maxPollTimes}次),任务未完成`);
|
|
60
|
+
reject(new Error(`轮询超时(${maxPollTimes}次),任务未完成`));
|
|
55
61
|
}
|
|
56
62
|
const { result, data, message } = Object.assign({}, await callback());
|
|
57
63
|
if (result === 'failed') {
|
|
58
64
|
clearInterval(timer);
|
|
59
|
-
reject(`任务处理失败:${message}`);
|
|
65
|
+
reject(new Error(`任务处理失败:${message}`));
|
|
60
66
|
}
|
|
61
67
|
if (result === 'success') {
|
|
62
68
|
clearInterval(timer);
|
|
@@ -89,14 +95,14 @@ module.exports = fp(async (fastify, options) => {
|
|
|
89
95
|
.catch(e => {
|
|
90
96
|
return task.update({
|
|
91
97
|
status: 'failed',
|
|
92
|
-
error: e.stack,
|
|
98
|
+
error: (e.stack || '').replaceAll(process.cwd(), '/server'),
|
|
93
99
|
completedAt: new Date()
|
|
94
100
|
});
|
|
95
101
|
});
|
|
96
102
|
} catch (e) {
|
|
97
103
|
await task.update({
|
|
98
104
|
status: 'failed',
|
|
99
|
-
error: e.stack,
|
|
105
|
+
error: (e.stack || '').replaceAll(process.cwd(), '/server'),
|
|
100
106
|
completedAt: new Date()
|
|
101
107
|
});
|
|
102
108
|
}
|