@kne/fastify-task 0.1.6 → 0.1.8

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.
@@ -92,20 +92,31 @@ module.exports = fp(async (fastify, options) => {
92
92
  .catch(error => {
93
93
  return task.update({
94
94
  status: 'failed',
95
- error: error.toString(),
95
+ error: error.stack,
96
96
  completedAt: new Date()
97
97
  });
98
98
  });
99
99
  } catch (error) {
100
100
  await task.update({
101
101
  status: 'failed',
102
- error: error.toString(),
102
+ error: error.stack,
103
103
  completedAt: new Date()
104
104
  });
105
105
  }
106
106
  };
107
107
 
108
108
  const runner = async () => {
109
+ const runningTaskCount = await models.task.count({
110
+ where: {
111
+ runnerType: 'system',
112
+ status: 'running'
113
+ }
114
+ });
115
+ const limit = options.limit - runningTaskCount;
116
+ if (limit <= 0) {
117
+ fastify.log.info(`当前运行中的系统任务数(${runningTaskCount})已达上限(${options.limit}),暂不执行新任务`);
118
+ return;
119
+ }
109
120
  const pendingTasks = await models.task.findAll({
110
121
  where: {
111
122
  runnerType: 'system',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-task",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "用于编排任务,追踪任务执行状态,结果",
5
5
  "main": "index.js",
6
6
  "scripts": {