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

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 (87) hide show
  1. package/lib/chevre/eventEmitter/task.d.ts +8 -23
  2. package/lib/chevre/eventEmitter/task.js +2 -2
  3. package/lib/chevre/repo/adminAsyncAction.d.ts +2 -2
  4. package/lib/chevre/repo/adminScheduledTask.d.ts +1 -1
  5. package/lib/chevre/repo/adminTask.d.ts +31 -8
  6. package/lib/chevre/repo/adminTask.js +41 -26
  7. package/lib/chevre/repo/aggregateScheduledTask.d.ts +32 -0
  8. package/lib/chevre/repo/aggregateScheduledTask.js +136 -0
  9. package/lib/chevre/repo/asyncAction.d.ts +2 -2
  10. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +1 -0
  11. package/lib/chevre/repo/mongoose/schemas/task.d.ts +2 -5
  12. package/lib/chevre/repo/mongoose/schemas/task.js +87 -96
  13. package/lib/chevre/repo/orderInTransaction.d.ts +0 -3
  14. package/lib/chevre/repo/orderInTransaction.js +30 -22
  15. package/lib/chevre/repo/scheduledTask.d.ts +5 -2
  16. package/lib/chevre/repo/scheduledTask.js +3 -25
  17. package/lib/chevre/repo/task.d.ts +25 -172
  18. package/lib/chevre/repo/task.js +19 -475
  19. package/lib/chevre/repo/taskDelayed.d.ts +74 -0
  20. package/lib/chevre/repo/taskDelayed.js +195 -0
  21. package/lib/chevre/repo/taskRunning.d.ts +35 -0
  22. package/lib/chevre/repo/taskRunning.js +89 -0
  23. package/lib/chevre/repository.d.ts +10 -0
  24. package/lib/chevre/repository.js +24 -2
  25. package/lib/chevre/service/aggregation/system.d.ts +10 -2
  26. package/lib/chevre/service/aggregation/system.js +42 -0
  27. package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +5 -25
  28. package/lib/chevre/service/asyncAction.d.ts +2 -2
  29. package/lib/chevre/service/asyncAction.js +1 -4
  30. package/lib/chevre/service/asyncActionHandler/onOperationFailed.d.ts +2 -2
  31. package/lib/chevre/service/asyncActionHandler/onOperationFailed.js +0 -2
  32. package/lib/chevre/service/asyncActionHandler.d.ts +4 -4
  33. package/lib/chevre/service/asyncActionHandler.js +11 -13
  34. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +1 -1
  35. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +0 -4
  36. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +19 -19
  37. package/lib/chevre/service/order/confirmPayTransaction.js +4 -1
  38. package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +4 -4
  39. package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +2 -2
  40. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +2 -2
  41. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +2 -2
  42. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +1 -1
  43. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +2 -2
  44. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
  45. package/lib/chevre/service/payment/any/findAcceptAction.d.ts +0 -4
  46. package/lib/chevre/service/payment/any/findAcceptAction.js +19 -19
  47. package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +0 -4
  48. package/lib/chevre/service/payment/any/findAuthorizeAction.js +19 -19
  49. package/lib/chevre/service/payment/any/findCheckAction.d.ts +0 -4
  50. package/lib/chevre/service/payment/any/findCheckAction.js +19 -19
  51. package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +0 -2
  52. package/lib/chevre/service/payment/any/publishPaymentUrl.js +2 -2
  53. package/lib/chevre/service/project.d.ts +0 -3
  54. package/lib/chevre/service/project.js +0 -1
  55. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -2
  56. package/lib/chevre/service/scheduledTask.d.ts +1 -4
  57. package/lib/chevre/service/scheduledTask.js +3 -10
  58. package/lib/chevre/service/scheduledTaskHandler/onOperationFailed.js +1 -2
  59. package/lib/chevre/service/scheduledTaskHandler.js +0 -13
  60. package/lib/chevre/service/task/acceptCOAOffer.js +1 -14
  61. package/lib/chevre/service/task/authorizePayment.js +1 -7
  62. package/lib/chevre/service/task/checkMovieTicket.js +1 -7
  63. package/lib/chevre/service/task/confirmReserveTransaction.js +3 -1
  64. package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +4 -1
  65. package/lib/chevre/service/task/importEventsFromCOA.js +4 -1
  66. package/lib/chevre/service/task/importOffersFromCOA.js +5 -5
  67. package/lib/chevre/service/task/publishPaymentUrl.js +2 -13
  68. package/lib/chevre/service/task/syncResourcesFromCOA.js +1 -5
  69. package/lib/chevre/service/task/voidReserveTransaction.js +5 -8
  70. package/lib/chevre/service/task.d.ts +3 -22
  71. package/lib/chevre/service/task.js +8 -40
  72. package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +3 -2
  73. package/lib/chevre/service/taskHandler/onOperationFailed.js +5 -16
  74. package/lib/chevre/service/taskHandler.d.ts +1 -2
  75. package/lib/chevre/service/taskHandler.js +7 -53
  76. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +8 -4
  77. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +55 -103
  78. package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -0
  79. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +14 -10
  80. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +13 -3
  81. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +48 -51
  82. package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
  83. package/lib/chevre/service/transaction/returnOrder.js +15 -13
  84. package/lib/chevre/service/transaction.d.ts +2 -0
  85. package/lib/chevre/service/transaction.js +0 -2
  86. package/lib/chevre/taskSettings.d.ts +4 -4
  87. package/package.json +2 -2
@@ -13,7 +13,7 @@ function onOperationFailed(params) {
13
13
  error = { message: String(error) };
14
14
  }
15
15
  const endDate = new Date();
16
- // remainingNumberOfTries<=0ならAborted(2025-08-04~)
16
+ // remainingNumberOfTries<=0ならAborted
17
17
  const isRetryable = task.remainingNumberOfTries > 0;
18
18
  if (isRetryable) {
19
19
  const result = {
@@ -35,7 +35,6 @@ function onOperationFailed(params) {
35
35
  }
36
36
  else {
37
37
  // 予定タスクは分析連携不要
38
- // await informTaskIfNeeded({ task, executionEndDate: endDate })(repos);
39
38
  const result = {
40
39
  executedAt: now,
41
40
  endDate,
@@ -1,14 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.taskLoader = void 0;
7
4
  exports.executeScheduledTask = executeScheduledTask;
8
- const debug_1 = __importDefault(require("debug"));
9
5
  const factory_1 = require("../factory");
10
6
  const onOperationFailed_1 = require("./scheduledTaskHandler/onOperationFailed");
11
- const debug = (0, debug_1.default)('chevre-domain:service:scheduledTaskHandler');
12
7
  exports.taskLoader = {
13
8
  load: (taskName) => {
14
9
  return import(`./task/${taskName}.js`);
@@ -19,18 +14,10 @@ exports.taskLoader = {
19
14
  */
20
15
  function executeScheduledTask(task) {
21
16
  const now = new Date();
22
- debug('executing an executableTask...', task, now);
23
17
  return async (settings, options) => {
24
18
  const scheduledTaskRepo = new (await import('../repo/scheduledTask.js')).ScheduledTaskRepo(settings.connection);
25
19
  try {
26
20
  // 予定タスクのexpiresはDBのttl基準なので期限検証はしない
27
- // if (task.expires instanceof Date) {
28
- // const taskExpired: boolean = moment(now)
29
- // .isAfter(task.expires);
30
- // if (taskExpired) {
31
- // throw new factory.errors.Internal(`task expired [expires:${task.expires}]`);
32
- // }
33
- // }
34
21
  // remainingNumberOfTries<0ならcallを実行しない(2025-08-04~)
35
22
  // リトライを繰り返した後、不明の原因でRunningのまま残ってしまったタスクがリトライされたケース
36
23
  const { remainingNumberOfTries } = task;
@@ -7,9 +7,6 @@ const acceptCOAOffer_1 = require("../../repo/action/acceptCOAOffer");
7
7
  const authorizeOffer_1 = require("../../repo/action/authorizeOffer");
8
8
  const credentials_1 = require("../../repo/credentials");
9
9
  const event_1 = require("../../repo/event");
10
- // import { OrderInTransactionRepo } from '../../repo/orderInTransaction';
11
- // import { OrderNumberRepo } from '../../repo/orderNumber';
12
- // import { ProjectRepo } from '../../repo/project';
13
10
  const reserveInterface_1 = require("../../repo/reserveInterface");
14
11
  const integration_1 = require("../../repo/setting/integration");
15
12
  const placeOrder_1 = require("../../repo/transaction/placeOrder");
@@ -19,14 +16,10 @@ let coaAuthClient;
19
16
  * タスク実行関数
20
17
  */
21
18
  function call(params) {
22
- return async ({ connection, redisClient }, options) => {
19
+ return async ({ connection, redisClient }) => {
23
20
  if (redisClient === undefined) {
24
21
  throw new factory_1.factory.errors.Argument('settings', 'redisClient required');
25
22
  }
26
- // 遅延実行(executeByName)には対応しない
27
- if (!options.executeById) {
28
- return;
29
- }
30
23
  const settings = new integration_1.IntegrationSettingRepo({ connection });
31
24
  const reserveInterfaceRepo = new reserveInterface_1.ReserveInterfaceRepo(connection);
32
25
  const coaAPI = await reserveInterfaceRepo.findOne({ project: { id: { $eq: params.project.id } } });
@@ -57,7 +50,6 @@ function call(params) {
57
50
  });
58
51
  }
59
52
  const actionRepo = new acceptCOAOffer_1.AcceptCOAOfferActionRepo(connection);
60
- // const transactionProcessRepo = new TransactionProcessRepo(redisClient, { lockExpiresInSeconds: 120 });
61
53
  try {
62
54
  const coaIntegrationSettings = await settings.getByKey('coa');
63
55
  const reserveService = new coa_service_1.COA.service.Reserve({
@@ -86,8 +78,6 @@ function call(params) {
86
78
  action: actionRepo,
87
79
  authorizeOfferAction: new authorizeOffer_1.AuthorizeOfferActionRepo(connection),
88
80
  event: new event_1.EventRepo(connection),
89
- // orderNumber: new OrderNumberRepo({ connection }),
90
- // project: new ProjectRepo(connection),
91
81
  placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
92
82
  reserveService,
93
83
  masterService
@@ -104,9 +94,6 @@ function call(params) {
104
94
  })({
105
95
  action: actionRepo,
106
96
  event: new event_1.EventRepo(connection),
107
- // orderInTransaction: new OrderInTransactionRepo(connection),
108
- // orderNumber: new OrderNumberRepo({ connection }),
109
- // project: new ProjectRepo(connection),
110
97
  placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
111
98
  reserveService,
112
99
  masterService
@@ -34,19 +34,13 @@ const any_1 = require("../payment/any");
34
34
  * タスク実行関数
35
35
  */
36
36
  function call(params) {
37
- return async ({ connection, redisClient }, options) => {
37
+ return async ({ connection, redisClient }) => {
38
38
  if (redisClient === undefined) {
39
39
  throw new factory_1.factory.errors.Argument('settings', 'redisClient required');
40
40
  }
41
- // 遅延実行(executeByName)には対応しない
42
- if (!options.executeById) {
43
- return;
44
- }
45
41
  let callResult;
46
42
  const settings = new integration_1.IntegrationSettingRepo({ connection });
47
- // const actionRepo = new ActionRepo(connection);
48
43
  const authorizePaymentMethodActionRepo = new authorizePaymentMethod_1.AuthorizePaymentMethodActionRepo(connection);
49
- // const transactionProcessRepo = new TransactionProcessRepo(redisClient, { lockExpiresInSeconds: 120 });
50
44
  const paymentServiceId = params.data.object.issuedThrough.id;
51
45
  const credentialsExpireInSeconds = (await settings.getByKey('movieticketReserve')).credentialsExpireInSeconds;
52
46
  const useCredentialsRepo = typeof paymentServiceId === 'string' && paymentServiceId !== ''
@@ -9,23 +9,17 @@ const paymentService_1 = require("../../repo/paymentService");
9
9
  const paymentServiceProvider_1 = require("../../repo/paymentServiceProvider");
10
10
  const sellerPaymentAccepted_1 = require("../../repo/sellerPaymentAccepted");
11
11
  const integration_1 = require("../../repo/setting/integration");
12
- // import { TransactionProcessRepo } from '../../repo/transactionProcess';
13
12
  const pay_1 = require("../assetTransaction/pay");
14
13
  /**
15
14
  * タスク実行関数
16
15
  */
17
16
  function call(params) {
18
- return async ({ connection, redisClient }, options) => {
17
+ return async ({ connection, redisClient }) => {
19
18
  if (redisClient === undefined) {
20
19
  throw new factory_1.factory.errors.Argument('settings', 'redisClient required');
21
20
  }
22
- // 遅延実行(executeByName)には対応しない
23
- if (!options.executeById) {
24
- return;
25
- }
26
21
  const settings = new integration_1.IntegrationSettingRepo({ connection });
27
22
  const actionRepo = new checkMovieTicket_1.CheckMovieTicketActionRepo(connection);
28
- // const transactionProcessRepo = new TransactionProcessRepo(redisClient, { lockExpiresInSeconds: 120 });
29
23
  const paymentServiceId = params.data.object[0]?.id;
30
24
  const credentialsExpireInSeconds = (await settings.getByKey('movieticketReserve')).credentialsExpireInSeconds;
31
25
  const useCredentialsRepo = typeof paymentServiceId === 'string' && paymentServiceId !== ''
@@ -247,7 +247,9 @@ function onConfirmed(params, options) {
247
247
  },
248
248
  useOnOrderStatusChanged: options.useOnOrderStatusChanged === true
249
249
  };
250
+ const taskIdentifier = (0, util_1.format)('%s:%s:%s:%s', params.project.id, factory_1.factory.taskName.OnAssetTransactionStatusChanged, onAssetTransactionStatusChangedTaskData.purpose.orderNumber, onAssetTransactionStatusChangedTaskData.object.transactionNumber);
250
251
  const onAssetTransactionStatusChangedTask = {
252
+ identifier: taskIdentifier,
251
253
  project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
252
254
  name: factory_1.factory.taskName.OnAssetTransactionStatusChanged,
253
255
  status: factory_1.factory.taskStatus.Ready,
@@ -257,7 +259,7 @@ function onConfirmed(params, options) {
257
259
  executionResults: [],
258
260
  data: onAssetTransactionStatusChangedTaskData
259
261
  };
260
- await repos.task.createOnAssetTransactionStatusChangedTaskIfNotExist(onAssetTransactionStatusChangedTask);
262
+ await repos.task.runTaskByIdentifier(onAssetTransactionStatusChangedTask);
261
263
  }
262
264
  };
263
265
  }
@@ -60,7 +60,10 @@ function call(params) {
60
60
  endpoint: coaAuthClient.options.endpoint, // same as authClient(2024-07-17~)
61
61
  auth: coaAuthClient
62
62
  }, { timeout: (await settings.getByKey('coa')).timeoutReserve });
63
- await EventAggregationService.importFromCOA(params.data)({
63
+ await EventAggregationService.importFromCOA({
64
+ ...params.data,
65
+ project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project }
66
+ })({
64
67
  event: new event_1.EventRepo(connection),
65
68
  reserveService
66
69
  });
@@ -67,7 +67,10 @@ function call(params) {
67
67
  endpoint: coaAuthClient.options.endpoint, // same as authClient(2024-07-17~)
68
68
  auth: coaAuthClient
69
69
  }, { timeout: (await settings.getByKey('coa')).timeoutMaster });
70
- await EventService.importFromCOA(params.data)({
70
+ await EventService.importFromCOA({
71
+ ...params.data,
72
+ project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project }
73
+ })({
71
74
  action: new action_1.ActionRepo(connection),
72
75
  categoryCode: new categoryCode_1.CategoryCodeRepo(connection),
73
76
  creativeWork: new creativeWork_1.CreativeWorkRepo(connection),
@@ -65,22 +65,22 @@ function call(params) {
65
65
  const settings = new integration_1.IntegrationSettingRepo({ connection });
66
66
  const aggregateOfferRepo = new aggregateOffer_1.AggregateOfferRepo(connection);
67
67
  const categoryCodeRepo = new categoryCode_1.CategoryCodeRepo(connection);
68
- // const taskRepo = new TaskRepo(connection);
69
68
  const masterService = new coa_service_1.COA.service.Master({
70
69
  endpoint: coaAuthClient.options.endpoint, // same as authClient(2024-07-17~)
71
70
  auth: coaAuthClient
72
71
  }, { timeout: (await settings.getByKey('coa')).timeoutMaster });
73
72
  await OfferService.event.importFromCOA({
74
- project: { id: params.data.project.id },
73
+ project: { id: params.project.id },
75
74
  theaterCode: params.data.theaterCode,
76
75
  paymentMethodType4membershipCoupon
77
76
  })({
78
- // categoryCode: categoryCodeRepo,
79
77
  aggregateOffer: aggregateOfferRepo,
80
- // task: taskRepo,
81
78
  masterService
82
79
  });
83
- await OfferService.event.importCategoryCodesFromCOA(params.data)({
80
+ await OfferService.event.importCategoryCodesFromCOA({
81
+ ...params.data,
82
+ project: { id: params.project.id }
83
+ })({
84
84
  categoryCode: categoryCodeRepo,
85
85
  masterService
86
86
  });
@@ -10,10 +10,8 @@ const event_1 = require("../../repo/event");
10
10
  const eventSeries_1 = require("../../repo/eventSeries");
11
11
  const issuer_1 = require("../../repo/issuer");
12
12
  const orderInTransaction_1 = require("../../repo/orderInTransaction");
13
- // import { OrderNumberRepo } from '../../repo/orderNumber';
14
13
  const paymentService_1 = require("../../repo/paymentService");
15
14
  const paymentServiceProvider_1 = require("../../repo/paymentServiceProvider");
16
- // import { ProjectRepo } from '../../repo/project';
17
15
  const sellerPaymentAccepted_1 = require("../../repo/sellerPaymentAccepted");
18
16
  const integration_1 = require("../../repo/setting/integration");
19
17
  const ticket_1 = require("../../repo/ticket");
@@ -24,26 +22,19 @@ const any_1 = require("../payment/any");
24
22
  * タスク実行関数
25
23
  */
26
24
  function call(params) {
27
- return async ({ connection, redisClient }, options) => {
25
+ return async ({ connection, redisClient }) => {
28
26
  if (redisClient === undefined) {
29
27
  throw new factory_1.factory.errors.Argument('settings', 'redisClient required');
30
28
  }
31
- // 遅延実行(executeByName)には対応しない
32
- if (!options.executeById) {
33
- return;
34
- }
35
29
  const settings = new integration_1.IntegrationSettingRepo({ connection });
36
30
  const actionRepo = new acceptPay_1.AcceptPayActionRepo(connection);
37
- // const transactionProcessRepo = new TransactionProcessRepo(redisClient, { lockExpiresInSeconds: 120 });
38
31
  try {
39
- const { savePaymentMethodIdInTransaction, project: _project, ...publishPaymentUrlParams } = params.data;
32
+ const { savePaymentMethodIdInTransaction: _savePaymentMethodIdInTransaction, project: _project, ...publishPaymentUrlParams } = params.data;
40
33
  await (0, any_1.publishPaymentUrl)({
41
34
  ...publishPaymentUrlParams,
42
35
  project: { id: params.project.id },
43
36
  instrument: (Array.isArray(params.data.instrument)) ? params.data.instrument : [],
44
37
  sameAs: { id: params.id }
45
- }, {
46
- savePaymentMethodIdInTransaction: savePaymentMethodIdInTransaction === true
47
38
  })({
48
39
  acceptPayAction: actionRepo,
49
40
  authorizeInvoiceAction: new authorizeInvoice_1.AuthorizeInvoiceActionRepo(connection),
@@ -53,11 +44,9 @@ function call(params) {
53
44
  eventSeries: new eventSeries_1.EventSeriesRepo(connection),
54
45
  issuer: new issuer_1.IssuerRepo(connection),
55
46
  orderInTransaction: new orderInTransaction_1.OrderInTransactionRepo(connection),
56
- // orderNumber: new OrderNumberRepo({ connection }),
57
47
  paymentAccepted: new sellerPaymentAccepted_1.SellerPaymentAcceptedRepo(connection),
58
48
  paymentService: new paymentService_1.PaymentServiceRepo(connection),
59
49
  paymentServiceProvider: new paymentServiceProvider_1.PaymentServiceProviderRepo(connection),
60
- // project: new ProjectRepo(connection),
61
50
  ticket: new ticket_1.TicketRepo(connection),
62
51
  placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
63
52
  transactionNumber: new transactionNumber_1.TransactionNumberRepo({ connection })
@@ -24,14 +24,10 @@ let coaAuthClient;
24
24
  * タスク実行関数
25
25
  */
26
26
  function call(params) {
27
- return async ({ connection, redisClient }, options) => {
27
+ return async ({ connection, redisClient }) => {
28
28
  if (redisClient === undefined) {
29
29
  throw new factory_1.factory.errors.Argument('settings', 'redisClient required');
30
30
  }
31
- // 遅延実行(executeByName)には対応しない
32
- if (!options.executeById) {
33
- return;
34
- }
35
31
  const settings = new integration_1.IntegrationSettingRepo({ connection });
36
32
  const reserveInterfaceRepo = new reserveInterface_1.ReserveInterfaceRepo(connection);
37
33
  const coaAPI = await reserveInterfaceRepo.findOne({ project: { id: { $eq: params.project.id } } });
@@ -16,7 +16,6 @@ const setting_1 = require("../../repo/setting");
16
16
  const integration_1 = require("../../repo/setting/integration");
17
17
  const stockHolder_1 = require("../../repo/stockHolder");
18
18
  const task_1 = require("../../repo/task");
19
- // import { TransactionRepo } from '../../repo/transaction';
20
19
  const placeOrder_1 = require("../../repo/transaction/placeOrder");
21
20
  let coaAuthClientCreated = false;
22
21
  let coaAuthClient = new coa_service_1.COA.auth.RefreshToken({
@@ -28,16 +27,16 @@ let coaAuthClient = new coa_service_1.COA.auth.RefreshToken({
28
27
  * タスク実行関数
29
28
  */
30
29
  function call(params) {
31
- return async ({ connection, redisClient }, options) => {
30
+ return async ({ connection, redisClient }) => {
32
31
  if (redisClient === undefined) {
33
32
  throw new factory_1.factory.errors.Argument('settings', 'redisClient required');
34
33
  }
35
34
  const voidByActionId = typeof params.data.id === 'string';
36
35
  if (voidByActionId) {
37
- // 遅延実行(executeByName)には対応しない
38
- if (!options.executeById) {
39
- return;
40
- }
36
+ // // 遅延実行(executeByName)には対応しない
37
+ // if (!options.executeById) {
38
+ // return;
39
+ // }
41
40
  }
42
41
  if (!coaAuthClientCreated) {
43
42
  const reserveInterfaceRepo = new reserveInterface_1.ReserveInterfaceRepo(connection);
@@ -53,7 +52,6 @@ function call(params) {
53
52
  endpoint: coaAuthClient.options.endpoint, // same as authClient(2024-07-17~)
54
53
  auth: coaAuthClient
55
54
  }, { timeout: (await settings.getByKey('coa')).timeoutReserve });
56
- // const transactionProcessRepo = new TransactionProcessRepo(redisClient, { lockExpiresInSeconds: 120 });
57
55
  try {
58
56
  await (0, voidTransaction_1.voidTransaction)({
59
57
  ...params.data,
@@ -71,7 +69,6 @@ function call(params) {
71
69
  setting: new setting_1.SettingRepo(connection),
72
70
  task: new task_1.TaskRepo(connection),
73
71
  placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
74
- // transaction: new TransactionRepo(connection),
75
72
  reserveService
76
73
  }, settings);
77
74
  }
@@ -1,5 +1,4 @@
1
- import type { IExecuteSettings as IMinimumExecuteSettings, INextFunction, IReadyTask, IRunningTask } from '../eventEmitter/task';
2
- import { factory } from '../factory';
1
+ import type { IExecuteSettings as IMinimumExecuteSettings, IReadyTask, IRunningTask } from '../eventEmitter/task';
3
2
  import type { AggregationSettings } from '../taskSettings';
4
3
  interface IExecuteSettings extends IMinimumExecuteSettings {
5
4
  aggregationSettings?: AggregationSettings;
@@ -8,30 +7,12 @@ type IOperation<T> = (settings: IExecuteSettings) => Promise<T>;
8
7
  /**
9
8
  * タスク変更イベントを受けて実行する
10
9
  */
11
- declare function executeById(params: (IReadyTask | IRunningTask) & {
10
+ declare function executeTaskById(params: (Pick<IReadyTask, 'id' | 'status'> | Pick<IRunningTask, 'id' | 'status'>) & {
12
11
  executor: {
13
12
  /**
14
13
  * タスク実行者名称
15
14
  */
16
15
  name: string;
17
16
  };
18
- }, next?: INextFunction): IOperation<void>;
19
- declare function executeOneIfExists(params: {
20
- name: {
21
- $eq: factory.taskName;
22
- };
23
- executor: {
24
- /**
25
- * タスク実行者名称
26
- */
27
- name: string;
28
- };
29
- runsAt: {
30
- $lt: Date;
31
- };
32
- sort: {
33
- numberOfTried?: factory.sortType;
34
- runsAt?: factory.sortType;
35
- };
36
17
  }): IOperation<void>;
37
- export { executeById, executeOneIfExists };
18
+ export { executeTaskById };
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.executeById = executeById;
7
- exports.executeOneIfExists = executeOneIfExists;
6
+ exports.executeTaskById = executeTaskById;
8
7
  /**
9
8
  * タスクサービス
10
9
  */
@@ -14,57 +13,26 @@ const debug = (0, debug_1.default)('chevre-domain:service:task');
14
13
  /**
15
14
  * タスク変更イベントを受けて実行する
16
15
  */
17
- function executeById(params, next) {
16
+ function executeTaskById(params) {
18
17
  return async (settings) => {
19
- const taskRepo = new (await import('../repo/task.js')).TaskRepo(settings.connection);
20
- const { id, status, executor, expires } = params;
18
+ const taskRunningRepo = new (await import('../repo/taskRunning.js')).TaskRunningRepo(settings.connection);
19
+ const { id, status, executor } = params;
21
20
  let task = null;
22
21
  try {
23
22
  // support status: Running(2025-03-05~)
24
- task = await taskRepo.executeOneById({
23
+ task = await taskRunningRepo.executeOneById({
25
24
  id,
26
25
  status,
27
- executor: { name: executor.name },
28
- ...(expires instanceof Date) ? { expires } : undefined
26
+ executor: { name: executor.name }
29
27
  });
30
28
  }
31
29
  catch (error) {
32
30
  /* istanbul ignore next */
33
- debug('service.task.executeById error:', error);
31
+ debug('service.task.executeTaskById error:', error);
34
32
  }
35
33
  // タスクがなければ終了
36
34
  if (task !== null) {
37
- await (0, taskHandler_1.executeTask)(task, (typeof next === 'function') ? next : undefined)(settings, {
38
- executeById: true,
39
- executeByName: false
40
- });
41
- }
42
- };
43
- }
44
- function executeOneIfExists(params) {
45
- return async (settings) => {
46
- const taskRepo = new (await import('../repo/task.js')).TaskRepo(settings.connection);
47
- // 未実行のタスクを取得
48
- let task = null;
49
- try {
50
- task = await taskRepo.executeOneIfExists({
51
- executor: { name: params.executor.name },
52
- runsAt: { $lt: params.runsAt.$lt },
53
- name: params.name,
54
- sort: params.sort
55
- });
56
- debug('executable task found.', task, params.runsAt.$lt);
57
- }
58
- catch (error) {
59
- /* istanbul ignore next */
60
- debug('executeOne error:', error);
61
- }
62
- // タスクがなければ終了
63
- if (task !== null) {
64
- await (0, taskHandler_1.executeTask)(task)(settings, {
65
- executeById: false,
66
- executeByName: (typeof params.name?.$eq === 'string')
67
- });
35
+ await (0, taskHandler_1.executeTask)(task)(settings, {});
68
36
  }
69
37
  };
70
38
  }
@@ -1,7 +1,7 @@
1
- import type { INextFunction } from '../../eventEmitter/task';
2
1
  import { factory } from '../../factory';
3
2
  import type { SettingRepo } from '../../repo/setting';
4
3
  import type { TaskRepo } from '../../repo/task';
4
+ import type { TaskRunningRepo } from '../../repo/taskRunning';
5
5
  import type { IExecutableTask } from '../../taskSettings';
6
6
  /**
7
7
  * タスク実行失敗時処理
@@ -10,9 +10,10 @@ declare function onOperationFailed(params: {
10
10
  task: IExecutableTask<factory.taskName>;
11
11
  now: Date;
12
12
  error: any;
13
- next?: INextFunction;
13
+ next?: never;
14
14
  }): (repos: {
15
15
  setting: SettingRepo;
16
16
  task: TaskRepo;
17
+ taskRunning: TaskRunningRepo;
17
18
  }) => Promise<void>;
18
19
  export { onOperationFailed };
@@ -9,7 +9,7 @@ const informTaskIfNeeded_1 = require("./onOperationFailed/informTaskIfNeeded");
9
9
  function onOperationFailed(params) {
10
10
  return async (repos) => {
11
11
  let error = params.error;
12
- const { task, now, next } = params;
12
+ const { task, now } = params;
13
13
  if (error === null || typeof error !== 'object') {
14
14
  error = { message: String(error) };
15
15
  }
@@ -18,9 +18,6 @@ function onOperationFailed(params) {
18
18
  const isRetryable = task.remainingNumberOfTries > 0;
19
19
  if (isRetryable) {
20
20
  // 実験的に実行中タスク連携をしてみたが、ひとまず廃止(2026-07-01~)
21
- // if (USE_INFORM_TASK_RUNNING) {
22
- // await informTaskIfNeeded({ task, executionEndDate: endDate })(repos);
23
- // }
24
21
  const result = {
25
22
  executedAt: now,
26
23
  endDate,
@@ -33,14 +30,10 @@ function onOperationFailed(params) {
33
30
  }
34
31
  };
35
32
  // 失敗してもここではステータスを戻さない(Runningのまま待機)
36
- await repos.task.setExecutionResultAndStatus({
37
- id: task.id,
38
- remainingNumberOfTries: task.remainingNumberOfTries,
39
- name: task.name
40
- }, {
33
+ await repos.taskRunning.setExecutionResultAndStatus({ id: task.id }, {
41
34
  status: task.status,
42
35
  executionResult: result
43
- }, (typeof next === 'function') ? next : undefined);
36
+ });
44
37
  }
45
38
  else {
46
39
  // 分析連携(2025-08-05~)
@@ -59,14 +52,10 @@ function onOperationFailed(params) {
59
52
  stack: error.stack
60
53
  }
61
54
  };
62
- await repos.task.setExecutionResultAndStatus({
63
- id: task.id,
64
- remainingNumberOfTries: task.remainingNumberOfTries,
65
- name: task.name
66
- }, {
55
+ await repos.taskRunning.setExecutionResultAndStatus({ id: task.id }, {
67
56
  status: factory_1.factory.taskStatus.Aborted,
68
57
  executionResult: result
69
- }, (typeof next === 'function') ? next : undefined);
58
+ });
70
59
  }
71
60
  };
72
61
  }
@@ -1,4 +1,3 @@
1
- import type { INextFunction } from '../eventEmitter/task';
2
1
  import { factory } from '../factory';
3
2
  import type { ICallResult, ICallableTaskOperation, IExecutableTask, IExecutableTaskKeys, IOperationExecute } from '../taskSettings';
4
3
  export declare const taskLoader: {
@@ -9,5 +8,5 @@ export declare const taskLoader: {
9
8
  /**
10
9
  * タスクを実行する
11
10
  */
12
- declare function executeTask(task: IExecutableTask<factory.taskName>, next?: INextFunction): IOperationExecute<void>;
11
+ declare function executeTask(task: IExecutableTask<factory.taskName>): IOperationExecute<void>;
13
12
  export { ICallableTaskOperation, ICallResult, IExecutableTaskKeys, IOperationExecute, executeTask };
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.taskLoader = void 0;
7
7
  exports.executeTask = executeTask;
8
8
  const debug_1 = __importDefault(require("debug"));
9
- const moment_1 = __importDefault(require("moment"));
10
9
  const factory_1 = require("../factory");
11
10
  const onOperationFailed_1 = require("./taskHandler/onOperationFailed");
12
11
  const debug = (0, debug_1.default)('chevre-domain:service:taskHandler');
@@ -18,21 +17,15 @@ exports.taskLoader = {
18
17
  /**
19
18
  * タスクを実行する
20
19
  */
21
- function executeTask(task, next) {
20
+ function executeTask(task) {
22
21
  const now = new Date();
23
22
  debug('executing an executableTask...', task, now);
24
23
  return async (settings, options) => {
25
24
  const settingRepo = new (await import('../repo/setting.js')).SettingRepo(settings.connection);
26
25
  const taskRepo = new (await import('../repo/task.js')).TaskRepo(settings.connection);
26
+ const taskRunningRepo = new (await import('../repo/taskRunning.js')).TaskRunningRepo(settings.connection);
27
27
  try {
28
- // 期限検証(2024-04-23~)
29
- if (task.expires instanceof Date) {
30
- const taskExpired = (0, moment_1.default)(now)
31
- .isAfter(task.expires);
32
- if (taskExpired) {
33
- throw new factory_1.factory.errors.Internal(`task expired [expires:${task.expires}]`);
34
- }
35
- }
28
+ // タスクのexpiresは廃止済なので期限検証はなし(2026-08-07~)
36
29
  // remainingNumberOfTries<0ならcallを実行しない(2025-08-04~)
37
30
  // リトライを繰り返した後、不明の原因でRunningのまま残ってしまったタスクがリトライされたケース
38
31
  const { remainingNumberOfTries } = task;
@@ -44,40 +37,6 @@ function executeTask(task, next) {
44
37
  const { call } = await exports.taskLoader.load(task.name); // testが書きづらいのでtaskLoader経由で呼ぶ
45
38
  const callResult = await call(task)(settings, options);
46
39
  // ICallableTaskOperationSimpleを廃止(2026-07-22~)
47
- // let callResult: ICallResult | undefined;
48
- // switch (task.name) {
49
- // case factory.taskName.AcceptCOAOffer:
50
- // case factory.taskName.AggregateOnSystem:
51
- // case factory.taskName.AuthorizePayment:
52
- // case factory.taskName.CancelPendingReservation:
53
- // case factory.taskName.CheckMovieTicket:
54
- // case factory.taskName.CheckResource:
55
- // case factory.taskName.CreateAccountingReport:
56
- // case factory.taskName.HandleNotification:
57
- // case factory.taskName.ImportEventCapacitiesFromCOA:
58
- // case factory.taskName.ImportEventsFromCOA:
59
- // case factory.taskName.ImportOffersFromCOA:
60
- // case factory.taskName.InvalidatePaymentUrl:
61
- // case factory.taskName.OnAuthorizationCreated:
62
- // case factory.taskName.OnResourceDeleted:
63
- // case factory.taskName.Pay:
64
- // case factory.taskName.PublishPaymentUrl:
65
- // case factory.taskName.Refund:
66
- // case factory.taskName.VoidPayTransaction:
67
- // case factory.taskName.VoidReserveTransaction:
68
- // case factory.taskName.ConfirmPayTransaction:
69
- // case factory.taskName.ConfirmReserveTransaction:
70
- // case factory.taskName.ReturnPayTransaction:
71
- // case factory.taskName.ReturnReserveTransaction:
72
- // case factory.taskName.SendEmailMessage:
73
- // case factory.taskName.SyncResourcesFromCOA:
74
- // case factory.taskName.TriggerWebhook:
75
- // case factory.taskName.UseReservation:
76
- // callResult = await (call as ICallableTaskOperation)(task)(settings, options);
77
- // break;
78
- // default:
79
- // await (call as ICallableTaskOperationSimple)(task.data)(settings); // TODO discontinue
80
- // }
81
40
  const result = {
82
41
  executedAt: now,
83
42
  endDate: new Date(),
@@ -89,20 +48,15 @@ function executeTask(task, next) {
89
48
  }
90
49
  : ''
91
50
  };
92
- await taskRepo.setExecutionResultAndStatus({
93
- id: task.id,
94
- remainingNumberOfTries,
95
- name: task.name
96
- }, {
51
+ await taskRunningRepo.setExecutionResultAndStatus({ id: task.id }, {
97
52
  status: factory_1.factory.taskStatus.Executed,
98
53
  executionResult: result
99
- }, (typeof next === 'function') ? next : undefined);
54
+ });
100
55
  }
101
56
  catch (error) {
102
57
  await (0, onOperationFailed_1.onOperationFailed)({
103
- task, now, error,
104
- ...(typeof next === 'function') ? { next } : undefined
105
- })({ setting: settingRepo, task: taskRepo });
58
+ task, now, error
59
+ })({ setting: settingRepo, task: taskRepo, taskRunning: taskRunningRepo });
106
60
  }
107
61
  };
108
62
  }