@nocobase/plugin-async-task-manager 2.0.0-alpha.56 → 2.0.0-alpha.57

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.
@@ -8,15 +8,15 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.0.0-alpha.56",
11
+ "@nocobase/client": "2.0.0-alpha.57",
12
12
  "react": "18.2.0",
13
- "@nocobase/utils": "2.0.0-alpha.56",
13
+ "@nocobase/utils": "2.0.0-alpha.57",
14
14
  "lodash": "4.17.21",
15
- "@nocobase/server": "2.0.0-alpha.56",
16
- "@nocobase/logger": "2.0.0-alpha.56",
17
- "@nocobase/database": "2.0.0-alpha.56",
15
+ "@nocobase/server": "2.0.0-alpha.57",
16
+ "@nocobase/logger": "2.0.0-alpha.57",
17
+ "@nocobase/database": "2.0.0-alpha.57",
18
18
  "antd": "5.24.2",
19
19
  "react-i18next": "11.18.6",
20
20
  "dayjs": "1.11.13",
21
- "@nocobase/actions": "2.0.0-alpha.56"
21
+ "@nocobase/actions": "2.0.0-alpha.57"
22
22
  };
@@ -130,31 +130,43 @@ class BaseTaskManager {
130
130
  cleanup = async () => {
131
131
  this.logger.debug("Running cleanup for completed tasks...");
132
132
  const TaskRepo = this.app.db.getRepository("asyncTasks");
133
- const tasksToCleanup = await TaskRepo.find({
134
- fields: ["id"],
135
- filter: {
136
- $or: [
137
- {
138
- status: [import_constants.TASK_STATUS.SUCCEEDED, import_constants.TASK_STATUS.FAILED],
139
- doneAt: {
140
- $lt: new Date(Date.now() - this.cleanupDelay)
133
+ try {
134
+ const tasksToCleanup = await TaskRepo.find({
135
+ fields: ["id"],
136
+ filter: {
137
+ $or: [
138
+ {
139
+ status: [import_constants.TASK_STATUS.SUCCEEDED, import_constants.TASK_STATUS.FAILED],
140
+ doneAt: {
141
+ $lt: new Date(Date.now() - this.cleanupDelay)
142
+ }
143
+ },
144
+ {
145
+ status: import_constants.TASK_STATUS.CANCELED
141
146
  }
142
- },
143
- {
144
- status: import_constants.TASK_STATUS.CANCELED
145
- }
146
- ]
147
+ ]
148
+ }
149
+ });
150
+ this.logger.debug(`Found ${tasksToCleanup.length} tasks to cleanup`);
151
+ if (tasksToCleanup.length) {
152
+ for (const task of tasksToCleanup) {
153
+ this.tasks.delete(task.id);
154
+ this.progressThrottles.delete(task.id);
155
+ }
156
+ await TaskRepo.destroy({
157
+ filterByTk: tasksToCleanup.map((task) => task.id),
158
+ individualHooks: true
159
+ });
160
+ }
161
+ } catch (error) {
162
+ this.logger.error(`DB error during cleanup: ${error.message}. Will stop cleanup timer.`, { error });
163
+ if (error.name === "SequelizeConnectionAcquireTimeoutError") {
164
+ if (this.cleanupTimer) {
165
+ clearInterval(this.cleanupTimer);
166
+ this.cleanupTimer = null;
167
+ }
147
168
  }
148
- });
149
- this.logger.debug(`Found ${tasksToCleanup.length} tasks to cleanup`);
150
- for (const task of tasksToCleanup) {
151
- this.tasks.delete(task.id);
152
- this.progressThrottles.delete(task.id);
153
169
  }
154
- await TaskRepo.destroy({
155
- filterByTk: tasksToCleanup.map((task) => task.id),
156
- individualHooks: true
157
- });
158
170
  };
159
171
  getThrottledProgressEmitter(taskId, userId) {
160
172
  if (!this.progressThrottles.has(taskId)) {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "Manage and monitor asynchronous tasks such as data import/export. Support task progress tracking and notification.",
7
7
  "description.ru-RU": "Управление асинхронными задачами и мониторинг (например, импорт/экспорт данных). Поддержка отслеживания прогресса и уведомлений о задачах.",
8
8
  "description.zh-CN": "管理和监控数据导入导出等异步任务。支持任务进度跟踪和通知。",
9
- "version": "2.0.0-alpha.56",
9
+ "version": "2.0.0-alpha.57",
10
10
  "main": "dist/server/index.js",
11
11
  "peerDependencies": {
12
12
  "@nocobase/client": "2.x",
@@ -17,5 +17,5 @@
17
17
  "dependencies": {
18
18
  "p-queue": "^6.6.2"
19
19
  },
20
- "gitHead": "a26a7c3422ea8089e0f04c89c9d32ff25bc09a0c"
20
+ "gitHead": "b9ec8bc83fd86a9cadfc4fb2f87a4e015061b289"
21
21
  }