@chevre/domain 26.0.0-alpha.0 → 26.0.0-alpha.10

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.
Files changed (59) hide show
  1. package/lib/chevre/repo/adminAsyncAction.d.ts +19 -0
  2. package/lib/chevre/repo/adminAsyncAction.js +86 -0
  3. package/lib/chevre/repo/adminScheduledTask.d.ts +20 -0
  4. package/lib/chevre/repo/adminScheduledTask.js +95 -0
  5. package/lib/chevre/repo/aggregateScheduledTask.d.ts +32 -0
  6. package/lib/chevre/repo/aggregateScheduledTask.js +136 -0
  7. package/lib/chevre/repo/asyncAction.d.ts +3 -8
  8. package/lib/chevre/repo/asyncAction.js +0 -108
  9. package/lib/chevre/repo/asyncActionLegacy.d.ts +23 -0
  10. package/lib/chevre/repo/asyncActionLegacy.js +59 -0
  11. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +2 -4
  12. package/lib/chevre/repo/scheduledTask.d.ts +1 -1
  13. package/lib/chevre/repo/scheduledTaskLegacy.d.ts +39 -0
  14. package/lib/chevre/repo/scheduledTaskLegacy.js +96 -0
  15. package/lib/chevre/repo/scheduledTaskMigration.d.ts +21 -0
  16. package/lib/chevre/repo/scheduledTaskMigration.js +70 -0
  17. package/lib/chevre/repo/task.d.ts +35 -68
  18. package/lib/chevre/repo/task.js +257 -177
  19. package/lib/chevre/repository.d.ts +25 -0
  20. package/lib/chevre/repository.js +57 -2
  21. package/lib/chevre/service/aggregation/system.d.ts +10 -2
  22. package/lib/chevre/service/aggregation/system.js +42 -0
  23. package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +5 -25
  24. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +1 -1
  25. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +0 -4
  26. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +19 -19
  27. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +2 -2
  28. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +1 -1
  29. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +1 -1
  30. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +1 -1
  31. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
  32. package/lib/chevre/service/payment/any/findAcceptAction.d.ts +0 -4
  33. package/lib/chevre/service/payment/any/findAcceptAction.js +19 -19
  34. package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +0 -4
  35. package/lib/chevre/service/payment/any/findAuthorizeAction.js +19 -19
  36. package/lib/chevre/service/payment/any/findCheckAction.d.ts +0 -4
  37. package/lib/chevre/service/payment/any/findCheckAction.js +19 -19
  38. package/lib/chevre/service/reserve/confirmReservation.js +19 -26
  39. package/lib/chevre/service/reserve/factory.d.ts +0 -3
  40. package/lib/chevre/service/reserve/factory.js +0 -4
  41. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.d.ts +4 -13
  42. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +21 -61
  43. package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +4 -1
  44. package/lib/chevre/service/task/importEventsFromCOA.js +4 -1
  45. package/lib/chevre/service/task/importOffersFromCOA.js +5 -5
  46. package/lib/chevre/service/task.d.ts +1 -20
  47. package/lib/chevre/service/task.js +0 -28
  48. package/lib/chevre/service/taskHandler.js +0 -34
  49. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +8 -4
  50. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +55 -103
  51. package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -0
  52. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +20 -10
  53. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +13 -3
  54. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +48 -51
  55. package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
  56. package/lib/chevre/service/transaction/returnOrder.js +21 -13
  57. package/lib/chevre/service/transaction.d.ts +2 -0
  58. package/lib/chevre/service/transaction.js +0 -2
  59. package/package.json +2 -2
@@ -23,23 +23,6 @@ const executableTaskProjection = {
23
23
  runsAt: 1,
24
24
  expires: 1
25
25
  };
26
- const AVAILABLE_PROJECT_FIELDS = [
27
- 'alternateName',
28
- 'identifier',
29
- 'description',
30
- 'project',
31
- 'name',
32
- 'status',
33
- 'runsAt',
34
- 'remainingNumberOfTries',
35
- 'lastTriedAt',
36
- 'numberOfTried',
37
- 'executionResults',
38
- 'executor',
39
- 'data',
40
- 'dateAborted',
41
- 'expires'
42
- ];
43
26
  /**
44
27
  * タスクリポジトリ
45
28
  */
@@ -48,31 +31,6 @@ class TaskRepo {
48
31
  constructor(connection) {
49
32
  this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
50
33
  }
51
- async runImmediately(params,
52
- // support customr function(2025-05-25~)
53
- next) {
54
- const { expires } = params;
55
- if (!(expires instanceof Date)) {
56
- throw new factory_1.factory.errors.Argument('expires', 'must be Date');
57
- }
58
- const savingTask = {
59
- ...params,
60
- status: factory_1.factory.taskStatus.Ready,
61
- numberOfTried: 0,
62
- executionResults: []
63
- };
64
- const result = await this.taskModel.insertMany(savingTask, { rawResult: true });
65
- const id = result.insertedIds?.[0]?.toHexString();
66
- if (typeof id !== 'string') {
67
- throw new factory_1.factory.errors.Internal('task not saved');
68
- }
69
- task_1.taskEventEmitter.emitTaskStatusChanged({
70
- id,
71
- status: factory_1.factory.taskStatus.Ready,
72
- expires // emit expires(2025-03-31~)
73
- }, next);
74
- return { id };
75
- }
76
34
  async saveMany(taskAttributes) {
77
35
  const emitImmediately = true; // always true(2026-07-30~)
78
36
  // const emitImmediately = options?.emitImmediately === true;
@@ -132,17 +90,24 @@ class TaskRepo {
132
90
  /**
133
91
  * タスク識別子から冪等作成する
134
92
  * reimplement createIfNotExistByIdentifier(2025-03-28~)
93
+ * reimplement runTaskByIdentifier(2026-08-03~)
135
94
  */
136
- async createIfNotExistByAlternateName(params) {
95
+ async runTaskByIdentifier(params) {
137
96
  const emitImmediately = true; // always true(2026-07-30~)
97
+ if (typeof params.identifier !== 'string' || params.identifier.length === 0) {
98
+ throw new factory_1.factory.errors.ArgumentNull('identifier');
99
+ }
138
100
  if (typeof params.alternateName !== 'string' || params.alternateName.length === 0) {
139
101
  throw new factory_1.factory.errors.ArgumentNull('alternateName');
140
102
  }
103
+ if (params.identifier !== params.alternateName) {
104
+ throw new factory_1.factory.errors.Argument('identifier,alternateName not matched');
105
+ }
141
106
  let createdTask;
142
107
  const filterQuery = {
143
108
  'project.id': { $eq: params.project.id },
144
109
  name: { $eq: params.name },
145
- alternateName: { $exists: true, $eq: params.alternateName }
110
+ identifier: { $exists: true, $eq: params.identifier }
146
111
  };
147
112
  const projection = {
148
113
  _id: 0,
@@ -160,7 +125,7 @@ class TaskRepo {
160
125
  catch (error) {
161
126
  let throwsError = true;
162
127
  if (await (0, errorHandler_1.isMongoDuplicateError)(error)) {
163
- // すでにalternateNameが存在する場合ok
128
+ // すでにidentifierが存在する場合ok
164
129
  throwsError = false;
165
130
  createdTask = await this.taskModel.findOne(filterQuery, projection)
166
131
  .lean()
@@ -180,7 +145,7 @@ class TaskRepo {
180
145
  }
181
146
  }
182
147
  else {
183
- throw new factory_1.factory.errors.Internal(`falied in creating a task unexpectedly. ${params.alternateName}`);
148
+ throw new factory_1.factory.errors.Internal(`falied in creating a task unexpectedly. ${params.identifier}`);
184
149
  }
185
150
  }
186
151
  // /**
@@ -284,58 +249,76 @@ class TaskRepo {
284
249
  }
285
250
  return doc;
286
251
  }
252
+ // 不要なので廃止(2026-08-04~)
253
+ // /**
254
+ // * Readyのタスクをname指定でひとつRunningに変更する
255
+ // */
256
+ // public async executeOneIfExists(params: {
257
+ // name: {
258
+ // $eq: factory.taskName;
259
+ // // $nin?: factory.taskName[]; // discontinue(2025-08-07~)
260
+ // };
261
+ // executor: { name: string };
262
+ // runsAt: {
263
+ // $lt: Date;
264
+ // };
265
+ // sort: {
266
+ // numberOfTried?: factory.sortType; // トライ回数の少なさ優先
267
+ // runsAt?: factory.sortType; // 実行予定日時の早さ優先
268
+ // };
269
+ // }): Promise<IExecutableTask<factory.taskName> | null> {
270
+ // if (!(params.runsAt.$lt instanceof Date)) {
271
+ // throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
272
+ // }
273
+ // const nameEq = params.name?.$eq;
274
+ // // const nameNin = params.name?.$nin;
275
+ // const doc = await this.taskModel.findOneAndUpdate(
276
+ // {
277
+ // status: { $eq: factory.taskStatus.Ready },
278
+ // runsAt: { $lt: params.runsAt.$lt },
279
+ // ...(typeof nameEq === 'string')
280
+ // ? {
281
+ // name: {
282
+ // ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined
283
+ // // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
284
+ // }
285
+ // }
286
+ // : undefined
287
+ // },
288
+ // {
289
+ // $set: {
290
+ // status: factory.taskStatus.Running, // 実行中に変更
291
+ // lastTriedAt: new Date(),
292
+ // executor: params.executor
293
+ // },
294
+ // $inc: {
295
+ // remainingNumberOfTries: -1, // 残りトライ可能回数減らす
296
+ // numberOfTried: 1 // トライ回数増やす
297
+ // }
298
+ // },
299
+ // {
300
+ // new: true,
301
+ // projection: executableTaskProjection,
302
+ // ...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
303
+ // ? { sort: params.sort }
304
+ // : undefined
305
+ // }
306
+ // )
307
+ // .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
308
+ // .lean<IExecutableTask<factory.taskName>>() // lean(2024-09-26~)
309
+ // .exec();
310
+ // if (doc === null) {
311
+ // return null;
312
+ // }
313
+ // return doc;
314
+ // }
287
315
  /**
288
- * Readyのタスクをname指定でひとつRunningに変更する
289
- */
290
- async executeOneIfExists(params) {
291
- if (!(params.runsAt.$lt instanceof Date)) {
292
- throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
293
- }
294
- const nameEq = params.name?.$eq;
295
- // const nameNin = params.name?.$nin;
296
- const doc = await this.taskModel.findOneAndUpdate({
297
- status: { $eq: factory_1.factory.taskStatus.Ready },
298
- runsAt: { $lt: params.runsAt.$lt },
299
- ...(typeof nameEq === 'string')
300
- ? {
301
- name: {
302
- ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined
303
- // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
304
- }
305
- }
306
- : undefined
307
- }, {
308
- $set: {
309
- status: factory_1.factory.taskStatus.Running, // 実行中に変更
310
- lastTriedAt: new Date(),
311
- executor: params.executor
312
- },
313
- $inc: {
314
- remainingNumberOfTries: -1, // 残りトライ可能回数減らす
315
- numberOfTried: 1 // トライ回数増やす
316
- }
317
- }, {
318
- new: true,
319
- projection: executableTaskProjection,
320
- ...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
321
- ? { sort: params.sort }
322
- : undefined
323
- })
324
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
325
- .lean() // lean(2024-09-26~)
326
- .exec();
327
- if (doc === null) {
328
- return null;
329
- }
330
- return doc;
331
- }
332
- /**
316
+ * 潜在的に実行されるべきタスクをカウントする
333
317
  * add(2025-03-16~)
334
318
  */
335
319
  async countPotentiallyRunning(params) {
336
320
  const { runsAt, limit, name } = params;
337
321
  const nameEq = name?.$eq;
338
- // const nameNin = name?.$nin;
339
322
  const nameIn = name?.$in;
340
323
  if (!(runsAt.$lt instanceof Date)) {
341
324
  throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
@@ -347,7 +330,6 @@ class TaskRepo {
347
330
  ? {
348
331
  name: {
349
332
  ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined,
350
- // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined,
351
333
  ...(Array.isArray(nameIn)) ? { $in: nameIn } : undefined
352
334
  }
353
335
  }
@@ -361,28 +343,16 @@ class TaskRepo {
361
343
  return { count };
362
344
  }
363
345
  /**
364
- * 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
346
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更する
365
347
  */
366
- async emitRunningIfExists(params) {
367
- if (!(params.runsAt.$lt instanceof Date)) {
368
- throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
369
- }
348
+ async runDelayedTask(params) {
349
+ const { filter } = params;
370
350
  const projection = {
371
351
  _id: 0,
372
352
  id: { $toString: '$_id' },
373
353
  name: 1
374
354
  };
375
- const nameEq = params.name?.$eq;
376
- // const nameNin = params.name?.$nin;
377
- // const nameIn = params.name?.$in;
378
- const { nameFilterBeforeRunsAt } = params;
379
- const filter = {
380
- status: { $eq: factory_1.factory.taskStatus.Ready },
381
- ...(nameFilterBeforeRunsAt) ? { name: params.name } : undefined,
382
- runsAt: { $lt: params.runsAt.$lt },
383
- ...(!nameFilterBeforeRunsAt) ? { name: params.name } : undefined
384
- };
385
- const doc = await this.taskModel.findOneAndUpdate(filter, {
355
+ return this.taskModel.findOneAndUpdate(filter, {
386
356
  $set: {
387
357
  status: factory_1.factory.taskStatus.Running, // 実行中に変更
388
358
  lastTriedAt: new Date(),
@@ -402,9 +372,58 @@ class TaskRepo {
402
372
  .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
403
373
  .lean()
404
374
  .exec();
375
+ }
376
+ /**
377
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
378
+ */
379
+ async emitRunningIfExistsByName(params) {
380
+ if (!(params.runsAt.$lt instanceof Date)) {
381
+ throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
382
+ }
383
+ // const projection: ProjectionType<IDocType> = {
384
+ // _id: 0,
385
+ // id: { $toString: '$_id' },
386
+ // name: 1
387
+ // };
388
+ // インデックス'executeOneByNameIfExists'を想定したfilter
389
+ const filter = {
390
+ status: { $eq: factory_1.factory.taskStatus.Ready },
391
+ runsAt: { $lt: params.runsAt.$lt },
392
+ name: params.name
393
+ };
394
+ const doc = await this.runDelayedTask({
395
+ filter,
396
+ sort: params.sort,
397
+ executor: params.executor
398
+ });
399
+ // const doc = await this.taskModel.findOneAndUpdate(
400
+ // filter,
401
+ // {
402
+ // $set: {
403
+ // status: factory.taskStatus.Running, // 実行中に変更
404
+ // lastTriedAt: new Date(),
405
+ // executor: params.executor
406
+ // },
407
+ // $inc: {
408
+ // remainingNumberOfTries: -1, // 残りトライ可能回数減らす
409
+ // numberOfTried: 1 // トライ回数増やす
410
+ // }
411
+ // },
412
+ // {
413
+ // new: true,
414
+ // projection,
415
+ // ...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
416
+ // ? { sort: params.sort }
417
+ // : undefined
418
+ // }
419
+ // )
420
+ // .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
421
+ // .lean<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'>>()
422
+ // .exec();
405
423
  if (doc === null) {
406
424
  return null;
407
425
  }
426
+ const nameEq = params.name?.$eq;
408
427
  let changedTask;
409
428
  if (typeof nameEq === 'string') {
410
429
  changedTask = {
@@ -423,32 +442,78 @@ class TaskRepo {
423
442
  return doc;
424
443
  }
425
444
  /**
426
- * Readyのままで期限切れのタスクをExpiredに変更する
445
+ * 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
446
+ * taskNameで絞らない
447
+ * 2026-08-04~
427
448
  */
428
- async makeExpiredMany(params) {
429
- const { expiresLt } = params;
430
- if (!(expiresLt instanceof Date)) {
431
- throw new factory_1.factory.errors.Argument('expiresLt', 'must be Date');
449
+ async emitRunningIfExistsNoName(params) {
450
+ if (!(params.runsAt.$lt instanceof Date)) {
451
+ throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
432
452
  }
433
- return this.taskModel.updateMany({
453
+ // インデックス'executeOneByNameIfExists'を想定したfilter
454
+ const filter = {
434
455
  status: { $eq: factory_1.factory.taskStatus.Ready },
435
- expires: { $exists: true, $lt: expiresLt }
456
+ runsAt: { $lt: params.runsAt.$lt }
457
+ };
458
+ const doc = await this.runDelayedTask({
459
+ filter,
460
+ sort: {
461
+ runsAt: factory_1.factory.sortType.Ascending // ソートはrunsAtのみにしてみる(2026-08-04~)
462
+ },
463
+ executor: params.executor
464
+ });
465
+ if (doc === null) {
466
+ return null;
467
+ }
468
+ const changedTask = {
469
+ id: doc.id,
470
+ status: factory_1.factory.taskStatus.Running
471
+ };
472
+ task_1.taskEventEmitter.emitTaskStatusChanged(changedTask);
473
+ return doc;
474
+ }
475
+ /**
476
+ * Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
477
+ */
478
+ async retryTasks(params) {
479
+ const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
480
+ .add(-params.intervalInMinutes, 'minutes')
481
+ .toDate();
482
+ // const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
483
+ // const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
484
+ return this.taskModel.updateMany(
485
+ // name: 'retry'のindexと連動しているので、条件の順序などには注意すること
486
+ // @see schemas/task
487
+ {
488
+ status: { $eq: factory_1.factory.taskStatus.Running },
489
+ lastTriedAt: {
490
+ $type: 'date',
491
+ $lt: lastTriedAtShoudBeLessThan
492
+ },
493
+ remainingNumberOfTries: { $gte: 1 },
494
+ // ...(typeof remainingNumberOfTriesGte === 'number')
495
+ // ? { remainingNumberOfTries: { $gte: remainingNumberOfTriesGte } }
496
+ // : undefined,
497
+ // ...(typeof remainingNumberOfTriesLte === 'number')
498
+ // ? { remainingNumberOfTries: { $lte: remainingNumberOfTriesLte } }
499
+ // : undefined,
500
+ // ...(Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined
436
501
  }, {
437
502
  $set: {
438
- status: factory_1.factory.taskStatus.Expired
503
+ status: factory_1.factory.taskStatus.Ready // 実行前に変更
439
504
  }
440
505
  })
441
506
  .exec();
442
507
  }
443
508
  /**
444
- * Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
509
+ * $lte:0Readyにする(特定のタスクを除いて) -> Readyにすれば自動的にAbortedになる
445
510
  */
446
- async retryMany(params) {
511
+ async retryAbortingTasksByName(params) {
447
512
  const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
448
513
  .add(-params.intervalInMinutes, 'minutes')
449
514
  .toDate();
450
- const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
451
- const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
515
+ // const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
516
+ // const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
452
517
  return this.taskModel.updateMany(
453
518
  // name: 'retry'のindexと連動しているので、条件の順序などには注意すること
454
519
  // @see schemas/task
@@ -458,12 +523,13 @@ class TaskRepo {
458
523
  $type: 'date',
459
524
  $lt: lastTriedAtShoudBeLessThan
460
525
  },
461
- ...(typeof remainingNumberOfTriesGte === 'number')
462
- ? { remainingNumberOfTries: { $gte: remainingNumberOfTriesGte } }
463
- : undefined,
464
- ...(typeof remainingNumberOfTriesLte === 'number')
465
- ? { remainingNumberOfTries: { $lte: remainingNumberOfTriesLte } }
466
- : undefined,
526
+ remainingNumberOfTries: { $lte: 0 },
527
+ // ...(typeof remainingNumberOfTriesGte === 'number')
528
+ // ? { remainingNumberOfTries: { $gte: remainingNumberOfTriesGte } }
529
+ // : undefined,
530
+ // ...(typeof remainingNumberOfTriesLte === 'number')
531
+ // ? { remainingNumberOfTries: { $lte: remainingNumberOfTriesLte } }
532
+ // : undefined,
467
533
  ...(Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined
468
534
  }, {
469
535
  $set: {
@@ -472,6 +538,30 @@ class TaskRepo {
472
538
  })
473
539
  .exec();
474
540
  }
541
+ /**
542
+ * $lte:0をReadyにする(特定のタスクを除いて) -> Readyにすれば自動的にAbortedになる
543
+ */
544
+ async retryAbortingTasks(params) {
545
+ const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
546
+ .add(-params.intervalInMinutes, 'minutes')
547
+ .toDate();
548
+ return this.taskModel.updateMany(
549
+ // name: 'retry'のindexと連動しているので、条件の順序などには注意すること
550
+ // @see schemas/task
551
+ {
552
+ status: { $eq: factory_1.factory.taskStatus.Running },
553
+ lastTriedAt: {
554
+ $type: 'date',
555
+ $lt: lastTriedAtShoudBeLessThan
556
+ },
557
+ remainingNumberOfTries: { $lte: 0 }
558
+ }, {
559
+ $set: {
560
+ status: factory_1.factory.taskStatus.Ready // 実行前に変更
561
+ }
562
+ })
563
+ .exec();
564
+ }
475
565
  /**
476
566
  * 実行中止済タスクを強制的にリトライ
477
567
  * 中止済タスクでなければ何もしない
@@ -490,26 +580,6 @@ class TaskRepo {
490
580
  })
491
581
  .exec();
492
582
  }
493
- async abortMany(params) {
494
- const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
495
- .add(-params.intervalInMinutes, 'minutes')
496
- .toDate();
497
- return this.taskModel.updateMany({
498
- status: { $eq: factory_1.factory.taskStatus.Running },
499
- lastTriedAt: {
500
- $type: 'date',
501
- $lt: lastTriedAtShoudBeLessThan
502
- },
503
- remainingNumberOfTries: { $eq: 0 },
504
- ...(Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined
505
- }, {
506
- $set: {
507
- status: factory_1.factory.taskStatus.Aborted,
508
- dateAborted: new Date()
509
- }
510
- })
511
- .exec();
512
- }
513
583
  /**
514
584
  * タスクIDから実行結果とステータスを保管する
515
585
  * Abortedの場合、dateAbortedもセットする
@@ -533,36 +603,46 @@ class TaskRepo {
533
603
  task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
534
604
  }
535
605
  }
536
- /**
537
- * タスクの状態を参照する
538
- * 非同期アクション移行が完了したら廃止する(2026-07-29~)
539
- */
540
- async findTaskById(params, inclusion) {
541
- let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
542
- if (Array.isArray(inclusion) && inclusion.length > 0) {
543
- positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
544
- }
545
- else {
546
- // no op
547
- }
548
- const projection = {
549
- _id: 0,
550
- id: { $toString: '$_id' },
551
- ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
552
- };
553
- const query = this.taskModel.findOne({
554
- _id: { $eq: params.id.$eq },
555
- 'project.id': { $eq: params.project.id.$eq },
556
- name: { $eq: params.name }
557
- }, projection);
558
- const doc = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
559
- .lean()
560
- .exec();
561
- if (doc === null) {
562
- return;
563
- }
564
- return doc;
565
- }
606
+ // 非同期アクションへ移行したので不要(2026-08-04~)
607
+ // /**
608
+ // * タスクの状態を参照する
609
+ // * 非同期アクション移行が完了したら廃止する(2026-07-29~)
610
+ // */
611
+ // public async findTaskById(
612
+ // params: {
613
+ // id: { $eq: string };
614
+ // project: { id: { $eq: string } };
615
+ // name: factory.taskName
616
+ // },
617
+ // inclusion: IKeyOfProjection[]
618
+ // ): Promise<(IDocType & { id: string } | undefined)> {
619
+ // let positiveProjectionFields: IKeyOfProjection[] = AVAILABLE_PROJECT_FIELDS;
620
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
621
+ // positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
622
+ // } else {
623
+ // // no op
624
+ // }
625
+ // const projection: ProjectionType<IDocType> = {
626
+ // _id: 0,
627
+ // id: { $toString: '$_id' },
628
+ // ...Object.fromEntries<1>(positiveProjectionFields.map((key) => ([key, 1])))
629
+ // };
630
+ // const query = this.taskModel.findOne(
631
+ // {
632
+ // _id: { $eq: params.id.$eq },
633
+ // 'project.id': { $eq: params.project.id.$eq },
634
+ // name: { $eq: params.name }
635
+ // },
636
+ // projection
637
+ // );
638
+ // const doc = await query.setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
639
+ // .lean<IDocType & { id: string }>()
640
+ // .exec();
641
+ // if (doc === null) {
642
+ // return;
643
+ // }
644
+ // return doc;
645
+ // }
566
646
  async deleteByProject(params) {
567
647
  await this.taskModel.deleteMany({
568
648
  'project.id': { $eq: params.project.id }
@@ -16,12 +16,16 @@ import type { CheckThingActionRepo } from './repo/action/checkThing';
16
16
  import type { PayActionRepo } from './repo/action/pay';
17
17
  import type { RefundActionRepo } from './repo/action/refund';
18
18
  import type { AsyncActionRepo } from './repo/asyncAction';
19
+ import type { AsyncActionLegacyRepo } from './repo/asyncActionLegacy';
19
20
  import type { AdditionalPropertyRepo } from './repo/additionalProperty';
21
+ import type { AdminAsyncActionRepo } from './repo/adminAsyncAction';
22
+ import type { AdminScheduledTaskRepo } from './repo/adminScheduledTask';
20
23
  import type { AdminTaskRepo } from './repo/adminTask';
21
24
  import type { AggregateActionRepo } from './repo/aggregateAction';
22
25
  import type { AggregateOfferRepo } from './repo/aggregateOffer';
23
26
  import type { AggregateOrderRepo } from './repo/aggregateOrder';
24
27
  import type { AggregateReservationRepo } from './repo/aggregateReservation';
28
+ import type { AggregateScheduledTaskRepo } from './repo/aggregateScheduledTask';
25
29
  import type { AggregateTaskRepo } from './repo/aggregateTask';
26
30
  import type { AggregationRepo } from './repo/aggregation';
27
31
  import type { AssetTransactionRepo } from './repo/assetTransaction';
@@ -89,6 +93,7 @@ import type { RateLimitSettingRepo } from './repo/setting/rateLimit';
89
93
  import type { WaiterSettingRepo } from './repo/setting/waiter';
90
94
  import type { StockHolderRepo } from './repo/stockHolder';
91
95
  import type { ScheduledTaskRepo } from './repo/scheduledTask';
96
+ import type { ScheduledTaskLegacyRepo } from './repo/scheduledTaskLegacy';
92
97
  import type { TaskRepo } from './repo/task';
93
98
  import type { TicketRepo } from './repo/ticket';
94
99
  import type { TransactionRepo } from './repo/transaction';
@@ -162,6 +167,14 @@ export type AdditionalProperty = AdditionalPropertyRepo;
162
167
  export declare namespace AdditionalProperty {
163
168
  function createInstance(...params: ConstructorParameters<typeof AdditionalPropertyRepo>): Promise<AdditionalPropertyRepo>;
164
169
  }
170
+ export type AdminAsyncAction = AdminAsyncActionRepo;
171
+ export declare namespace AdminAsyncAction {
172
+ function createInstance(...params: ConstructorParameters<typeof AdminAsyncActionRepo>): Promise<AdminAsyncActionRepo>;
173
+ }
174
+ export type AdminScheduledTask = AdminScheduledTaskRepo;
175
+ export declare namespace AdminScheduledTask {
176
+ function createInstance(...params: ConstructorParameters<typeof AdminScheduledTaskRepo>): Promise<AdminScheduledTaskRepo>;
177
+ }
165
178
  export type AdminTask = AdminTaskRepo;
166
179
  export declare namespace AdminTask {
167
180
  function createInstance(...params: ConstructorParameters<typeof AdminTaskRepo>): Promise<AdminTaskRepo>;
@@ -170,6 +183,10 @@ export type AggregateAction = AggregateActionRepo;
170
183
  export declare namespace AggregateAction {
171
184
  function createInstance(...params: ConstructorParameters<typeof AggregateActionRepo>): Promise<AggregateActionRepo>;
172
185
  }
186
+ export type AggregateScheduledTask = AggregateScheduledTaskRepo;
187
+ export declare namespace AggregateScheduledTask {
188
+ function createInstance(...params: ConstructorParameters<typeof AggregateScheduledTaskRepo>): Promise<AggregateScheduledTaskRepo>;
189
+ }
173
190
  export type AggregateTask = AggregateTaskRepo;
174
191
  export declare namespace AggregateTask {
175
192
  function createInstance(...params: ConstructorParameters<typeof AggregateTaskRepo>): Promise<AggregateTaskRepo>;
@@ -482,6 +499,10 @@ export type ScheduledTask = ScheduledTaskRepo;
482
499
  export declare namespace ScheduledTask {
483
500
  function createInstance(...params: ConstructorParameters<typeof ScheduledTaskRepo>): Promise<ScheduledTaskRepo>;
484
501
  }
502
+ export type ScheduledTaskLegacy = ScheduledTaskLegacyRepo;
503
+ export declare namespace ScheduledTaskLegacy {
504
+ function createInstance(...params: ConstructorParameters<typeof ScheduledTaskLegacyRepo>): Promise<ScheduledTaskLegacyRepo>;
505
+ }
485
506
  export type Task = TaskRepo;
486
507
  export declare namespace Task {
487
508
  function createInstance(...params: ConstructorParameters<typeof TaskRepo>): Promise<TaskRepo>;
@@ -490,6 +511,10 @@ export type AsyncAction = AsyncActionRepo;
490
511
  export declare namespace AsyncAction {
491
512
  function createInstance(...params: ConstructorParameters<typeof AsyncActionRepo>): Promise<AsyncActionRepo>;
492
513
  }
514
+ export type AsyncActionLegacy = AsyncActionLegacyRepo;
515
+ export declare namespace AsyncActionLegacy {
516
+ function createInstance(...params: ConstructorParameters<typeof AsyncActionLegacyRepo>): Promise<AsyncActionLegacyRepo>;
517
+ }
493
518
  export type Ticket = TicketRepo;
494
519
  export declare namespace Ticket {
495
520
  function createInstance(...params: ConstructorParameters<typeof TicketRepo>): Promise<TicketRepo>;