@kne/fastify-task 0.1.9 → 0.1.11

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.
@@ -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;
@@ -146,8 +152,8 @@ module.exports = fp(async (fastify, options) => {
146
152
  return task;
147
153
  };
148
154
 
149
- const cancel = async ({ id, targetId, targetType }) => {
150
- if (targetId && targetType) {
155
+ const cancel = async ({ id, targetId, targetType, type }) => {
156
+ if (targetId && targetType && type) {
151
157
  return await models.task.update(
152
158
  {
153
159
  status: 'canceled'
@@ -156,6 +162,7 @@ module.exports = fp(async (fastify, options) => {
156
162
  where: {
157
163
  targetId,
158
164
  targetType,
165
+ type,
159
166
  status: {
160
167
  [Op.in]: ['pending', 'running']
161
168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-task",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "用于编排任务,追踪任务执行状态,结果",
5
5
  "main": "index.js",
6
6
  "scripts": {