@chevre/domain 26.0.0-alpha.21 → 26.0.0-alpha.22

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.
@@ -4,6 +4,7 @@ exports.modelName = exports.indexes = void 0;
4
4
  exports.createSchema = createSchema;
5
5
  const mongoose_1 = require("mongoose");
6
6
  const writeConcern_1 = require("../writeConcern");
7
+ const factory_1 = require("../../../factory");
7
8
  const settings_1 = require("../../../settings");
8
9
  const modelName = 'Task';
9
10
  exports.modelName = modelName;
@@ -94,10 +95,11 @@ const indexes = [
94
95
  }
95
96
  }
96
97
  ],
97
- [
98
- { remainingNumberOfTries: 1, runsAt: -1 },
99
- { name: 'searchByRemainingNumberOfTries-v2' }
100
- ],
98
+ // discontinue(2026-08-08~)
99
+ // [
100
+ // { remainingNumberOfTries: 1, runsAt: -1 },
101
+ // { name: 'searchByRemainingNumberOfTries-v2' }
102
+ // ],
101
103
  [
102
104
  { 'data.id': 1, runsAt: -1 },
103
105
  {
@@ -107,10 +109,11 @@ const indexes = [
107
109
  }
108
110
  }
109
111
  ],
110
- [
111
- { status: 1, name: 1, numberOfTried: 1, runsAt: 1 },
112
- { name: 'executeOneByName' }
113
- ],
112
+ // 遅延タスク実行時のソート条件をrunsAtのみに統一したため、numberOfTriedを含めたインデックスはもう不要(2026-08-08~)
113
+ // [
114
+ // { status: 1, name: 1, numberOfTried: 1, runsAt: 1 },
115
+ // { name: 'executeOneByName' }
116
+ // ],
114
117
  [
115
118
  { status: 1, runsAt: 1, name: 1 },
116
119
  { name: 'executeOneByNameIfExists' } // add(2025-03-08~)
@@ -220,6 +223,27 @@ const indexes = [
220
223
  // ],
221
224
  ];
222
225
  exports.indexes = indexes;
226
+ const EXPIRE_AFTER_SECONDS = typeof process.env.TASK_EXPIRE_AFTER_SECONDS === 'string'
227
+ ? Number(process.env.TASK_EXPIRE_AFTER_SECONDS)
228
+ : undefined;
229
+ // 0より大きい数値が設定されている場合のみ ttlインデックスを追加
230
+ if (typeof EXPIRE_AFTER_SECONDS === 'number' && EXPIRE_AFTER_SECONDS > 0) {
231
+ indexes.push([
232
+ { runsAt: 1 },
233
+ {
234
+ name: 'ttlByRunsAt',
235
+ expireAfterSeconds: EXPIRE_AFTER_SECONDS,
236
+ partialFilterExpression: {
237
+ status: {
238
+ $in: [
239
+ factory_1.factory.taskStatus.Aborted,
240
+ factory_1.factory.taskStatus.Executed
241
+ ]
242
+ }
243
+ }
244
+ }
245
+ ]);
246
+ }
223
247
  /**
224
248
  * タスクスキーマ
225
249
  */
@@ -85,7 +85,7 @@ class TaskDelayedRepo {
85
85
  if (!(params.runsAt.$lt instanceof Date)) {
86
86
  throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
87
87
  }
88
- // インデックスについては、name指定であれば'executeOneByName'あるいは'runDelayedTaskByName'を想定
88
+ // インデックスについては、name指定であれば'runDelayedTaskByName'を想定
89
89
  const filter = {
90
90
  status: { $eq: factory_1.factory.taskStatus.Ready },
91
91
  name: params.name,
package/package.json CHANGED
@@ -88,5 +88,5 @@
88
88
  "postversion": "git push origin --tags",
89
89
  "prepublishOnly": "npm run clean && npm run build"
90
90
  },
91
- "version": "26.0.0-alpha.21"
91
+ "version": "26.0.0-alpha.22"
92
92
  }