@kne/fastify-task 1.0.0-alpha.1 → 1.0.1

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.
@@ -59,28 +59,32 @@ module.exports = fp(async (fastify, options) => {
59
59
  clearInterval(timer);
60
60
  reject(new Error(`轮询超时(${maxPollTimes}次),任务未完成`));
61
61
  }
62
- const pollingResult = Object.assign({}, await callback());
63
- const { result, data, message, progress } = pollingResult;
64
- if (typeof props?.task?.update === 'function') {
65
- await props.task.reload();
66
- await props.task.update(
67
- Object.assign(
68
- {},
69
- {
70
- pollCount: props.task.pollCount + 1,
71
- pollResults: [...props.task.pollResults, Object.assign({}, pollingResult, { time: new Date() })]
72
- },
73
- Number.isInteger(progress) ? { progress } : {}
74
- )
75
- );
76
- }
77
- if (result === 'failed') {
78
- clearInterval(timer);
79
- reject(new Error(`任务处理失败:${message}`));
80
- }
81
- if (result === 'success') {
82
- clearInterval(timer);
83
- resolve(data);
62
+ try {
63
+ const pollingResult = Object.assign({}, await callback());
64
+ const { result, data, message, progress } = pollingResult;
65
+ if (typeof props?.task?.update === 'function') {
66
+ await props.task.reload();
67
+ await props.task.update(
68
+ Object.assign(
69
+ {},
70
+ {
71
+ pollCount: props.task.pollCount + 1,
72
+ pollResults: [...props.task.pollResults, Object.assign({}, pollingResult, { time: new Date() })]
73
+ },
74
+ Number.isInteger(progress) ? { progress } : {}
75
+ )
76
+ );
77
+ }
78
+ if (result === 'failed') {
79
+ clearInterval(timer);
80
+ reject(new Error(`任务处理失败:${message}`));
81
+ }
82
+ if (result === 'success') {
83
+ clearInterval(timer);
84
+ resolve(data);
85
+ }
86
+ } catch (e) {
87
+ reject(e);
84
88
  }
85
89
  }, pollInterval);
86
90
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-task",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.1",
4
4
  "description": "用于编排任务,追踪任务执行状态,结果",
5
5
  "main": "index.js",
6
6
  "scripts": {