@chevre/domain 26.0.0-alpha.14 → 26.0.0-alpha.16
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.
- package/lib/chevre/eventEmitter/task.d.ts +8 -23
- package/lib/chevre/eventEmitter/task.js +2 -2
- package/lib/chevre/repo/scheduledTask.js +0 -21
- package/lib/chevre/repo/task.d.ts +1 -7
- package/lib/chevre/repo/task.js +1 -204
- package/lib/chevre/service/asyncAction.d.ts +2 -2
- package/lib/chevre/service/asyncAction.js +1 -1
- package/lib/chevre/service/asyncActionHandler/onOperationFailed.d.ts +2 -2
- package/lib/chevre/service/asyncActionHandler/onOperationFailed.js +0 -2
- package/lib/chevre/service/asyncActionHandler.d.ts +4 -4
- package/lib/chevre/service/asyncActionHandler.js +11 -13
- package/lib/chevre/service/order/confirmPayTransaction.js +4 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +1 -1
- package/lib/chevre/service/project.d.ts +0 -3
- package/lib/chevre/service/project.js +0 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +1 -1
- package/lib/chevre/service/task/confirmReserveTransaction.js +3 -1
- package/package.json +1 -1
|
@@ -16,9 +16,6 @@ interface IReadyTask {
|
|
|
16
16
|
id: string;
|
|
17
17
|
name?: factory.taskName;
|
|
18
18
|
status: factory.taskStatus.Ready;
|
|
19
|
-
remainingNumberOfTries?: never;
|
|
20
|
-
expires?: Date;
|
|
21
|
-
executionResult?: never;
|
|
22
19
|
}
|
|
23
20
|
/**
|
|
24
21
|
* タスク名不明の遅延実行中タスク
|
|
@@ -27,9 +24,6 @@ interface IRunningTask {
|
|
|
27
24
|
id: string;
|
|
28
25
|
status: factory.taskStatus.Running;
|
|
29
26
|
name?: never;
|
|
30
|
-
remainingNumberOfTries?: never;
|
|
31
|
-
expires?: never;
|
|
32
|
-
executionResult?: never;
|
|
33
27
|
}
|
|
34
28
|
/**
|
|
35
29
|
* タスク名指定での遅延実行中タスク
|
|
@@ -38,35 +32,26 @@ interface IRunningTaskByName {
|
|
|
38
32
|
id: string;
|
|
39
33
|
status: factory.taskStatus.Running;
|
|
40
34
|
name: factory.taskName;
|
|
41
|
-
remainingNumberOfTries?: never;
|
|
42
|
-
expires?: never;
|
|
43
|
-
executionResult?: never;
|
|
44
35
|
}
|
|
45
36
|
/**
|
|
46
|
-
*
|
|
37
|
+
* タスクステータス変更イベント発火時パラメータとしてのタスク
|
|
47
38
|
*/
|
|
48
|
-
|
|
39
|
+
type IChangedTask = IReadyTask | IRunningTask | IRunningTaskByName;
|
|
40
|
+
type IOperationExecute<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
41
|
+
interface ITaskAsNextFunctionParam {
|
|
49
42
|
id: string;
|
|
50
43
|
status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
|
|
51
44
|
name: factory.taskName;
|
|
52
|
-
executionResult: factory.task.IExecutionResult;
|
|
53
|
-
/**
|
|
54
|
-
* 実行されたタスクの残り試行回数
|
|
55
|
-
*/
|
|
56
|
-
remainingNumberOfTries: number;
|
|
57
|
-
expires?: never;
|
|
58
45
|
}
|
|
59
|
-
type
|
|
60
|
-
type
|
|
61
|
-
type INextFunction = (task: IExecutedTask) => IOperationExecute<void>;
|
|
62
|
-
type IOnTaskStatusChangedListener = (task: IChangedTask, next?: INextFunction) => void;
|
|
46
|
+
type IAsyncActionNextFunction = (task: ITaskAsNextFunctionParam) => IOperationExecute<void>;
|
|
47
|
+
type IOnTaskStatusChangedListener = (task: IChangedTask) => void;
|
|
63
48
|
type RedisClientType = ReturnType<typeof createClient>;
|
|
64
49
|
/**
|
|
65
50
|
* タスクイベントエミッター
|
|
66
51
|
*/
|
|
67
52
|
declare class TaskEventEmitter extends EventEmitter {
|
|
68
53
|
onTaskStatusChanged(listener: IOnTaskStatusChangedListener): void;
|
|
69
|
-
emitTaskStatusChanged(task: IChangedTask
|
|
54
|
+
emitTaskStatusChanged(task: IChangedTask): void;
|
|
70
55
|
}
|
|
71
56
|
declare const taskEventEmitter: TaskEventEmitter;
|
|
72
|
-
export { IChangedTask, IReadyTask, IRunningTask, IRunningTaskByName,
|
|
57
|
+
export { IChangedTask, IReadyTask, IRunningTask, IRunningTaskByName, IExecuteSettings, IOnTaskStatusChangedListener, taskEventEmitter, ITaskAsNextFunctionParam, IAsyncActionNextFunction };
|
|
@@ -14,8 +14,8 @@ class TaskEventEmitter extends events_1.EventEmitter {
|
|
|
14
14
|
this.on(EventName.OnTaskStatusChanged, listener);
|
|
15
15
|
}
|
|
16
16
|
// support next function required(2025-05-25~)
|
|
17
|
-
emitTaskStatusChanged(task
|
|
18
|
-
this.emit(EventName.OnTaskStatusChanged, task
|
|
17
|
+
emitTaskStatusChanged(task) {
|
|
18
|
+
this.emit(EventName.OnTaskStatusChanged, task);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
const taskEventEmitter = new TaskEventEmitter();
|
|
@@ -40,15 +40,6 @@ class ScheduledTaskRepo {
|
|
|
40
40
|
.map((objectId) => {
|
|
41
41
|
return { id: objectId.toHexString() };
|
|
42
42
|
});
|
|
43
|
-
// イベントは発火しない
|
|
44
|
-
// if (emitImmediately) {
|
|
45
|
-
// savedTasks.forEach((savedTask) => {
|
|
46
|
-
// taskEventEmitter.emitTaskStatusChanged({
|
|
47
|
-
// id: savedTask.id,
|
|
48
|
-
// status: factory.taskStatus.Ready
|
|
49
|
-
// });
|
|
50
|
-
// });
|
|
51
|
-
// }
|
|
52
43
|
return savedTasks;
|
|
53
44
|
}
|
|
54
45
|
else {
|
|
@@ -116,18 +107,6 @@ class ScheduledTaskRepo {
|
|
|
116
107
|
if (doc === null) {
|
|
117
108
|
return null;
|
|
118
109
|
}
|
|
119
|
-
// if (!noEmitEvent) {
|
|
120
|
-
// const changedTask: IRunningTaskByName = {
|
|
121
|
-
// id: doc.id,
|
|
122
|
-
// status: factory.taskStatus.Running,
|
|
123
|
-
// name: nameEq
|
|
124
|
-
// };
|
|
125
|
-
// taskEventEmitter.emitTaskStatusChanged(
|
|
126
|
-
// changedTask,
|
|
127
|
-
// // 現時点でタスク遅延実行ではnext指定なし(2026-07-30)
|
|
128
|
-
// // (typeof next === 'function') ? next : undefined
|
|
129
|
-
// );
|
|
130
|
-
// }
|
|
131
110
|
return doc;
|
|
132
111
|
}
|
|
133
112
|
/**
|
|
@@ -53,11 +53,10 @@ export declare class TaskRepo {
|
|
|
53
53
|
* reimplement runTaskByIdentifier(2026-08-03~)
|
|
54
54
|
*/
|
|
55
55
|
runTaskByIdentifier(params: ICreatingTask & {
|
|
56
|
-
alternateName
|
|
56
|
+
alternateName?: never;
|
|
57
57
|
identifier: string;
|
|
58
58
|
expires?: never;
|
|
59
59
|
}): Promise<void>;
|
|
60
|
-
createOnAssetTransactionStatusChangedTaskIfNotExist(params: Pick<factory.task.IAttributes<factory.taskName.OnAssetTransactionStatusChanged>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'>): Promise<void>;
|
|
61
60
|
/**
|
|
62
61
|
* Ready -> remainingNumberOfTriesが1減る
|
|
63
62
|
* Running -> findOneするだけ
|
|
@@ -112,11 +111,6 @@ export declare class TaskRepo {
|
|
|
112
111
|
status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
|
|
113
112
|
executionResult: factory.task.IExecutionResult;
|
|
114
113
|
}): Promise<void>;
|
|
115
|
-
deleteByProject(params: {
|
|
116
|
-
project: {
|
|
117
|
-
id: string;
|
|
118
|
-
};
|
|
119
|
-
}): Promise<void>;
|
|
120
114
|
/**
|
|
121
115
|
* 不要なタスクを削除する
|
|
122
116
|
*/
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -33,7 +33,6 @@ class TaskRepo {
|
|
|
33
33
|
}
|
|
34
34
|
async saveMany(taskAttributes) {
|
|
35
35
|
const emitImmediately = true; // always true(2026-07-30~)
|
|
36
|
-
// const emitImmediately = options?.emitImmediately === true;
|
|
37
36
|
if (taskAttributes.length > 0) {
|
|
38
37
|
const creatingTasks = taskAttributes.map(({ identifier, ...creatingTask }) => creatingTask); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
39
38
|
const result = await this.taskModel.insertMany(creatingTasks, { ordered: false, rawResult: true });
|
|
@@ -51,14 +50,7 @@ class TaskRepo {
|
|
|
51
50
|
status: factory_1.factory.taskStatus.Ready
|
|
52
51
|
});
|
|
53
52
|
});
|
|
54
|
-
// taskAttributes.forEach((savedTask) => {
|
|
55
|
-
// taskEventEmitter.emitTaskStatusChanged({
|
|
56
|
-
// name: savedTask.name,
|
|
57
|
-
// status: factory.taskStatus.Ready
|
|
58
|
-
// });
|
|
59
|
-
// });
|
|
60
53
|
}
|
|
61
|
-
// return result.ops;
|
|
62
54
|
return savedTasks;
|
|
63
55
|
}
|
|
64
56
|
else {
|
|
@@ -109,12 +101,6 @@ class TaskRepo {
|
|
|
109
101
|
if (typeof params.identifier !== 'string' || params.identifier.length === 0) {
|
|
110
102
|
throw new factory_1.factory.errors.ArgumentNull('identifier');
|
|
111
103
|
}
|
|
112
|
-
if (typeof params.alternateName !== 'string' || params.alternateName.length === 0) {
|
|
113
|
-
throw new factory_1.factory.errors.ArgumentNull('alternateName');
|
|
114
|
-
}
|
|
115
|
-
if (params.identifier !== params.alternateName) {
|
|
116
|
-
throw new factory_1.factory.errors.Argument('identifier,alternateName not matched');
|
|
117
|
-
}
|
|
118
104
|
let createdTask;
|
|
119
105
|
const filterQuery = {
|
|
120
106
|
'project.id': { $eq: params.project.id },
|
|
@@ -160,63 +146,6 @@ class TaskRepo {
|
|
|
160
146
|
throw new factory_1.factory.errors.Internal(`falied in creating a task unexpectedly. ${params.identifier}`);
|
|
161
147
|
}
|
|
162
148
|
}
|
|
163
|
-
// /**
|
|
164
|
-
// * 取引削除タスク冪等作成
|
|
165
|
-
// */
|
|
166
|
-
// public async createDeleteTransactionTaskIfNotExist(
|
|
167
|
-
// // resolve uniqueness of identifier(2025-03-27~)
|
|
168
|
-
// params: Pick<
|
|
169
|
-
// factory.task.IAttributes<factory.taskName.DeleteTransaction>,
|
|
170
|
-
// 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'
|
|
171
|
-
// >,
|
|
172
|
-
// options: IOptionOnCreate
|
|
173
|
-
// ): Promise<void> {
|
|
174
|
-
// if (params.data.object.specifyingMethod !== factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id) {
|
|
175
|
-
// throw new factory.errors.NotImplemented(`only ${factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id} implemented`);
|
|
176
|
-
// }
|
|
177
|
-
// const createdTask = await this.taskModel.findOneAndUpdate(
|
|
178
|
-
// {
|
|
179
|
-
// 'project.id': { $eq: params.project.id },
|
|
180
|
-
// name: { $eq: params.name },
|
|
181
|
-
// 'data.object.id': { $exists: true, $eq: params.data.object.id }
|
|
182
|
-
// },
|
|
183
|
-
// { $setOnInsert: params },
|
|
184
|
-
// { new: true, upsert: true }
|
|
185
|
-
// )
|
|
186
|
-
// .select({ _id: 1 })
|
|
187
|
-
// .exec();
|
|
188
|
-
// if (options.emitImmediately) {
|
|
189
|
-
// taskEventEmitter.emitTaskStatusChanged({
|
|
190
|
-
// id: createdTask.id,
|
|
191
|
-
// name: params.name,
|
|
192
|
-
// status: factory.taskStatus.Ready
|
|
193
|
-
// });
|
|
194
|
-
// }
|
|
195
|
-
// }
|
|
196
|
-
async createOnAssetTransactionStatusChangedTaskIfNotExist(params) {
|
|
197
|
-
const emitImmediately = true; // always true(2026-07-30~)
|
|
198
|
-
const createdTask = await this.taskModel.findOneAndUpdate({
|
|
199
|
-
'project.id': { $eq: params.project.id },
|
|
200
|
-
name: { $eq: params.name },
|
|
201
|
-
'data.object.transactionNumber': {
|
|
202
|
-
$exists: true,
|
|
203
|
-
$eq: String(params.data.object.transactionNumber)
|
|
204
|
-
},
|
|
205
|
-
'data.purpose.orderNumber': {
|
|
206
|
-
$exists: true,
|
|
207
|
-
$eq: String(params.data.purpose.orderNumber)
|
|
208
|
-
}
|
|
209
|
-
}, { $setOnInsert: params }, { new: true, upsert: true })
|
|
210
|
-
.select({ _id: 1 })
|
|
211
|
-
.exec();
|
|
212
|
-
if (emitImmediately) {
|
|
213
|
-
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
214
|
-
id: createdTask.id,
|
|
215
|
-
name: params.name,
|
|
216
|
-
status: factory_1.factory.taskStatus.Ready
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
149
|
/**
|
|
221
150
|
* Ready -> remainingNumberOfTriesが1減る
|
|
222
151
|
* Running -> findOneするだけ
|
|
@@ -261,69 +190,6 @@ class TaskRepo {
|
|
|
261
190
|
}
|
|
262
191
|
return doc;
|
|
263
192
|
}
|
|
264
|
-
// 不要なので廃止(2026-08-04~)
|
|
265
|
-
// /**
|
|
266
|
-
// * Readyのタスクをname指定でひとつRunningに変更する
|
|
267
|
-
// */
|
|
268
|
-
// public async executeOneIfExists(params: {
|
|
269
|
-
// name: {
|
|
270
|
-
// $eq: factory.taskName;
|
|
271
|
-
// // $nin?: factory.taskName[]; // discontinue(2025-08-07~)
|
|
272
|
-
// };
|
|
273
|
-
// executor: { name: string };
|
|
274
|
-
// runsAt: {
|
|
275
|
-
// $lt: Date;
|
|
276
|
-
// };
|
|
277
|
-
// sort: {
|
|
278
|
-
// numberOfTried?: factory.sortType; // トライ回数の少なさ優先
|
|
279
|
-
// runsAt?: factory.sortType; // 実行予定日時の早さ優先
|
|
280
|
-
// };
|
|
281
|
-
// }): Promise<IExecutableTask<factory.taskName> | null> {
|
|
282
|
-
// if (!(params.runsAt.$lt instanceof Date)) {
|
|
283
|
-
// throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
284
|
-
// }
|
|
285
|
-
// const nameEq = params.name?.$eq;
|
|
286
|
-
// // const nameNin = params.name?.$nin;
|
|
287
|
-
// const doc = await this.taskModel.findOneAndUpdate(
|
|
288
|
-
// {
|
|
289
|
-
// status: { $eq: factory.taskStatus.Ready },
|
|
290
|
-
// runsAt: { $lt: params.runsAt.$lt },
|
|
291
|
-
// ...(typeof nameEq === 'string')
|
|
292
|
-
// ? {
|
|
293
|
-
// name: {
|
|
294
|
-
// ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined
|
|
295
|
-
// // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
|
|
296
|
-
// }
|
|
297
|
-
// }
|
|
298
|
-
// : undefined
|
|
299
|
-
// },
|
|
300
|
-
// {
|
|
301
|
-
// $set: {
|
|
302
|
-
// status: factory.taskStatus.Running, // 実行中に変更
|
|
303
|
-
// lastTriedAt: new Date(),
|
|
304
|
-
// executor: params.executor
|
|
305
|
-
// },
|
|
306
|
-
// $inc: {
|
|
307
|
-
// remainingNumberOfTries: -1, // 残りトライ可能回数減らす
|
|
308
|
-
// numberOfTried: 1 // トライ回数増やす
|
|
309
|
-
// }
|
|
310
|
-
// },
|
|
311
|
-
// {
|
|
312
|
-
// new: true,
|
|
313
|
-
// projection: executableTaskProjection,
|
|
314
|
-
// ...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
|
|
315
|
-
// ? { sort: params.sort }
|
|
316
|
-
// : undefined
|
|
317
|
-
// }
|
|
318
|
-
// )
|
|
319
|
-
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
320
|
-
// .lean<IExecutableTask<factory.taskName>>() // lean(2024-09-26~)
|
|
321
|
-
// .exec();
|
|
322
|
-
// if (doc === null) {
|
|
323
|
-
// return null;
|
|
324
|
-
// }
|
|
325
|
-
// return doc;
|
|
326
|
-
// }
|
|
327
193
|
/**
|
|
328
194
|
* Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
|
|
329
195
|
*/
|
|
@@ -331,8 +197,6 @@ class TaskRepo {
|
|
|
331
197
|
const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
|
|
332
198
|
.add(-params.intervalInMinutes, 'minutes')
|
|
333
199
|
.toDate();
|
|
334
|
-
// const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
|
|
335
|
-
// const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
|
|
336
200
|
return this.taskModel.updateMany(
|
|
337
201
|
// name: 'retry'のindexと連動しているので、条件の順序などには注意すること
|
|
338
202
|
// @see schemas/task
|
|
@@ -342,14 +206,7 @@ class TaskRepo {
|
|
|
342
206
|
$type: 'date',
|
|
343
207
|
$lt: lastTriedAtShoudBeLessThan
|
|
344
208
|
},
|
|
345
|
-
remainingNumberOfTries: { $gte: 1 }
|
|
346
|
-
// ...(typeof remainingNumberOfTriesGte === 'number')
|
|
347
|
-
// ? { remainingNumberOfTries: { $gte: remainingNumberOfTriesGte } }
|
|
348
|
-
// : undefined,
|
|
349
|
-
// ...(typeof remainingNumberOfTriesLte === 'number')
|
|
350
|
-
// ? { remainingNumberOfTries: { $lte: remainingNumberOfTriesLte } }
|
|
351
|
-
// : undefined,
|
|
352
|
-
// ...(Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined
|
|
209
|
+
remainingNumberOfTries: { $gte: 1 }
|
|
353
210
|
}, {
|
|
354
211
|
$set: {
|
|
355
212
|
status: factory_1.factory.taskStatus.Ready // 実行前に変更
|
|
@@ -364,8 +221,6 @@ class TaskRepo {
|
|
|
364
221
|
const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
|
|
365
222
|
.add(-params.intervalInMinutes, 'minutes')
|
|
366
223
|
.toDate();
|
|
367
|
-
// const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
|
|
368
|
-
// const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
|
|
369
224
|
return this.taskModel.updateMany(
|
|
370
225
|
// name: 'retry'のindexと連動しているので、条件の順序などには注意すること
|
|
371
226
|
// @see schemas/task
|
|
@@ -376,12 +231,6 @@ class TaskRepo {
|
|
|
376
231
|
$lt: lastTriedAtShoudBeLessThan
|
|
377
232
|
},
|
|
378
233
|
remainingNumberOfTries: { $lte: 0 },
|
|
379
|
-
// ...(typeof remainingNumberOfTriesGte === 'number')
|
|
380
|
-
// ? { remainingNumberOfTries: { $gte: remainingNumberOfTriesGte } }
|
|
381
|
-
// : undefined,
|
|
382
|
-
// ...(typeof remainingNumberOfTriesLte === 'number')
|
|
383
|
-
// ? { remainingNumberOfTries: { $lte: remainingNumberOfTriesLte } }
|
|
384
|
-
// : undefined,
|
|
385
234
|
...(Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined
|
|
386
235
|
}, {
|
|
387
236
|
$set: {
|
|
@@ -447,58 +296,6 @@ class TaskRepo {
|
|
|
447
296
|
$push: { executionResults: executionResult }
|
|
448
297
|
})
|
|
449
298
|
.exec();
|
|
450
|
-
// discontinue next(2026-08-05~)
|
|
451
|
-
// // emit event(2025-05-26~)
|
|
452
|
-
// if (typeof next === 'function') {
|
|
453
|
-
// const changedTask: IExecutedTask = { id, name, status, remainingNumberOfTries, executionResult };
|
|
454
|
-
// taskEventEmitter.emitTaskStatusChanged(changedTask, next);
|
|
455
|
-
// }
|
|
456
|
-
}
|
|
457
|
-
// 非同期アクションへ移行したので不要(2026-08-04~)
|
|
458
|
-
// /**
|
|
459
|
-
// * タスクの状態を参照する
|
|
460
|
-
// * 非同期アクション移行が完了したら廃止する(2026-07-29~)
|
|
461
|
-
// */
|
|
462
|
-
// public async findTaskById(
|
|
463
|
-
// params: {
|
|
464
|
-
// id: { $eq: string };
|
|
465
|
-
// project: { id: { $eq: string } };
|
|
466
|
-
// name: factory.taskName
|
|
467
|
-
// },
|
|
468
|
-
// inclusion: IKeyOfProjection[]
|
|
469
|
-
// ): Promise<(IDocType & { id: string } | undefined)> {
|
|
470
|
-
// let positiveProjectionFields: IKeyOfProjection[] = AVAILABLE_PROJECT_FIELDS;
|
|
471
|
-
// if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
472
|
-
// positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
473
|
-
// } else {
|
|
474
|
-
// // no op
|
|
475
|
-
// }
|
|
476
|
-
// const projection: ProjectionType<IDocType> = {
|
|
477
|
-
// _id: 0,
|
|
478
|
-
// id: { $toString: '$_id' },
|
|
479
|
-
// ...Object.fromEntries<1>(positiveProjectionFields.map((key) => ([key, 1])))
|
|
480
|
-
// };
|
|
481
|
-
// const query = this.taskModel.findOne(
|
|
482
|
-
// {
|
|
483
|
-
// _id: { $eq: params.id.$eq },
|
|
484
|
-
// 'project.id': { $eq: params.project.id.$eq },
|
|
485
|
-
// name: { $eq: params.name }
|
|
486
|
-
// },
|
|
487
|
-
// projection
|
|
488
|
-
// );
|
|
489
|
-
// const doc = await query.setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
490
|
-
// .lean<IDocType & { id: string }>()
|
|
491
|
-
// .exec();
|
|
492
|
-
// if (doc === null) {
|
|
493
|
-
// return;
|
|
494
|
-
// }
|
|
495
|
-
// return doc;
|
|
496
|
-
// }
|
|
497
|
-
async deleteByProject(params) {
|
|
498
|
-
await this.taskModel.deleteMany({
|
|
499
|
-
'project.id': { $eq: params.project.id }
|
|
500
|
-
})
|
|
501
|
-
.exec();
|
|
502
299
|
}
|
|
503
300
|
/**
|
|
504
301
|
* 不要なタスクを削除する
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IExecuteSettings as IMinimumExecuteSettings,
|
|
1
|
+
import type { IExecuteSettings as IMinimumExecuteSettings, IAsyncActionNextFunction } from '../eventEmitter/task';
|
|
2
2
|
type IExecuteSettings = IMinimumExecuteSettings;
|
|
3
3
|
type IOperation<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
4
4
|
declare function executeAsyncActionById(params: {
|
|
@@ -12,5 +12,5 @@ declare function executeAsyncActionById(params: {
|
|
|
12
12
|
*/
|
|
13
13
|
name: string;
|
|
14
14
|
};
|
|
15
|
-
}, next
|
|
15
|
+
}, next: IAsyncActionNextFunction): IOperation<void>;
|
|
16
16
|
export { executeAsyncActionById };
|
|
@@ -27,7 +27,7 @@ function executeAsyncActionById(params, next) {
|
|
|
27
27
|
}
|
|
28
28
|
// タスクがなければ終了
|
|
29
29
|
if (task !== null) {
|
|
30
|
-
await (0, asyncActionHandler_1.executeAsyncAction)(task,
|
|
30
|
+
await (0, asyncActionHandler_1.executeAsyncAction)(task, next)(settings, {
|
|
31
31
|
executeById: true,
|
|
32
32
|
// executeByName: false // discontinue(2026-08-05~)
|
|
33
33
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ITaskAsNextFunctionParam } from '../../eventEmitter/task';
|
|
2
2
|
import type { AsyncActionRepo, IExecutableAsyncAction } from '../../repo/asyncAction';
|
|
3
3
|
/**
|
|
4
4
|
* タスク実行失敗時処理
|
|
@@ -10,6 +10,6 @@ declare function onOperationFailed(params: {
|
|
|
10
10
|
}): (repos: {
|
|
11
11
|
asyncAction: AsyncActionRepo;
|
|
12
12
|
}) => Promise<{
|
|
13
|
-
executedTask:
|
|
13
|
+
executedTask: ITaskAsNextFunctionParam;
|
|
14
14
|
}>;
|
|
15
15
|
export { onOperationFailed };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { IAsyncActionNextFunction } from '../eventEmitter/task';
|
|
2
|
+
import type { ICallableTaskOperation, IOperationExecute } from '../taskSettings';
|
|
3
3
|
import type { IExecutableAsyncAction } from '../repo/asyncAction';
|
|
4
4
|
export declare const taskLoader: {
|
|
5
5
|
load: (taskName: string) => Promise<{
|
|
@@ -9,5 +9,5 @@ export declare const taskLoader: {
|
|
|
9
9
|
/**
|
|
10
10
|
* 非同期アクションを実行する
|
|
11
11
|
*/
|
|
12
|
-
declare function executeAsyncAction(task: IExecutableAsyncAction, next
|
|
13
|
-
export {
|
|
12
|
+
declare function executeAsyncAction(task: IExecutableAsyncAction, next: IAsyncActionNextFunction): IOperationExecute<void>;
|
|
13
|
+
export { executeAsyncAction };
|
|
@@ -5,11 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.taskLoader = void 0;
|
|
7
7
|
exports.executeAsyncAction = executeAsyncAction;
|
|
8
|
-
const debug_1 = __importDefault(require("debug"));
|
|
9
8
|
const moment_1 = __importDefault(require("moment"));
|
|
10
9
|
const factory_1 = require("../factory");
|
|
11
10
|
const onOperationFailed_1 = require("./asyncActionHandler/onOperationFailed");
|
|
12
|
-
const debug = (0, debug_1.default)('chevre-domain:service:asyncActionHandler');
|
|
13
11
|
exports.taskLoader = {
|
|
14
12
|
load: (taskName) => {
|
|
15
13
|
return import(`./task/${taskName}.js`);
|
|
@@ -20,10 +18,9 @@ exports.taskLoader = {
|
|
|
20
18
|
*/
|
|
21
19
|
function executeAsyncAction(task, next) {
|
|
22
20
|
const now = new Date();
|
|
23
|
-
debug('executing an executableTask...', task, now);
|
|
24
21
|
return async (settings, options) => {
|
|
25
22
|
const asyncActionRepo = new (await import('../repo/asyncAction.js')).AsyncActionRepo(settings.connection);
|
|
26
|
-
let
|
|
23
|
+
let taskAsNextFunctionParam;
|
|
27
24
|
try {
|
|
28
25
|
// 期限検証(2024-04-23~)
|
|
29
26
|
if (task.expires instanceof Date) {
|
|
@@ -57,32 +54,33 @@ function executeAsyncAction(task, next) {
|
|
|
57
54
|
status: factory_1.factory.taskStatus.Executed,
|
|
58
55
|
executionResult: result
|
|
59
56
|
});
|
|
60
|
-
|
|
57
|
+
taskAsNextFunctionParam = {
|
|
61
58
|
id: task.id,
|
|
62
|
-
remainingNumberOfTries: 0, // one timeの前提なのでひとまず固定で0
|
|
63
59
|
name: task.name,
|
|
64
60
|
status: factory_1.factory.taskStatus.Executed,
|
|
65
|
-
executionResult: result
|
|
66
61
|
};
|
|
67
62
|
}
|
|
68
63
|
catch (error) {
|
|
69
64
|
const onOperationFailedResult = await (0, onOperationFailed_1.onOperationFailed)({
|
|
70
65
|
task, now, error,
|
|
71
66
|
})({ asyncAction: asyncActionRepo });
|
|
72
|
-
|
|
67
|
+
taskAsNextFunctionParam = {
|
|
68
|
+
id: onOperationFailedResult.executedTask.id,
|
|
69
|
+
name: onOperationFailedResult.executedTask.name,
|
|
70
|
+
status: onOperationFailedResult.executedTask.status
|
|
71
|
+
};
|
|
72
|
+
;
|
|
73
73
|
}
|
|
74
74
|
finally {
|
|
75
75
|
if (typeof next === 'function') {
|
|
76
|
-
if (
|
|
77
|
-
|
|
76
|
+
if (taskAsNextFunctionParam === undefined) {
|
|
77
|
+
taskAsNextFunctionParam = {
|
|
78
78
|
id: task.id,
|
|
79
|
-
remainingNumberOfTries: 0, // one timeの前提なのでひとまず固定で0
|
|
80
79
|
name: task.name,
|
|
81
80
|
status: factory_1.factory.taskStatus.Aborted,
|
|
82
|
-
executionResult: {} // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
83
81
|
};
|
|
84
82
|
}
|
|
85
|
-
await next(
|
|
83
|
+
await next(taskAsNextFunctionParam)(settings);
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
86
|
};
|
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.confirmPayTransaction = confirmPayTransaction;
|
|
37
|
+
const util_1 = require("util");
|
|
37
38
|
const factory_1 = require("../../factory");
|
|
38
39
|
// import type { TransactionRepo } from '../../repo/transaction';
|
|
39
40
|
const PayTransactionService = __importStar(require("../assetTransaction/pay"));
|
|
@@ -112,7 +113,9 @@ function onConfirmed(params) {
|
|
|
112
113
|
},
|
|
113
114
|
useOnOrderStatusChanged: params.useOnOrderStatusChanged === true
|
|
114
115
|
};
|
|
116
|
+
const taskIdentifier = (0, util_1.format)('%s:%s:%s:%s', params.project.id, factory_1.factory.taskName.OnAssetTransactionStatusChanged, onAssetTransactionStatusChangedTaskData.purpose.orderNumber, onAssetTransactionStatusChangedTaskData.object.transactionNumber);
|
|
115
117
|
const onAssetTransactionStatusChangedTask = {
|
|
118
|
+
identifier: taskIdentifier,
|
|
116
119
|
project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
117
120
|
name: factory_1.factory.taskName.OnAssetTransactionStatusChanged,
|
|
118
121
|
status: factory_1.factory.taskStatus.Ready,
|
|
@@ -122,7 +125,7 @@ function onConfirmed(params) {
|
|
|
122
125
|
executionResults: [],
|
|
123
126
|
data: onAssetTransactionStatusChangedTaskData
|
|
124
127
|
};
|
|
125
|
-
await repos.task.
|
|
128
|
+
await repos.task.runTaskByIdentifier(onAssetTransactionStatusChangedTask);
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
131
|
};
|
|
@@ -62,7 +62,7 @@ function createSendOrderTaskIfNotExist(params) {
|
|
|
62
62
|
};
|
|
63
63
|
const taskIdentifier = `${sendOrderTaskData.project.id}:${factory_1.factory.taskName.SendOrder}:${sendOrderTaskData.object.typeOf}:${sendOrderTaskData.object.orderNumber}`;
|
|
64
64
|
const sendOrderTask = {
|
|
65
|
-
alternateName: taskIdentifier,
|
|
65
|
+
// alternateName: taskIdentifier,
|
|
66
66
|
identifier: taskIdentifier,
|
|
67
67
|
project: params.order.project,
|
|
68
68
|
name: factory_1.factory.taskName.SendOrder,
|
|
@@ -92,7 +92,7 @@ function createOnAuthorizationCreatedTask(order) {
|
|
|
92
92
|
const taskRunsAt = new Date();
|
|
93
93
|
const taskIdentifier = `${order.project.id}:${factory_1.factory.taskName.OnAuthorizationCreated}:${factory_1.factory.transactionType.PlaceOrder}:${placeOrderTransaction?.id}`;
|
|
94
94
|
const task = {
|
|
95
|
-
alternateName: taskIdentifier,
|
|
95
|
+
// alternateName: taskIdentifier,
|
|
96
96
|
identifier: taskIdentifier,
|
|
97
97
|
name: factory_1.factory.taskName.OnAuthorizationCreated,
|
|
98
98
|
status: factory_1.factory.taskStatus.Ready,
|
|
@@ -53,7 +53,7 @@ function createConfirmPayTransactionTasks(order, simpleOrder) {
|
|
|
53
53
|
};
|
|
54
54
|
const taskIdentifier = (0, util_1.format)('%s:%s:%s:%s:%s:%s', order.project.id, factory_1.factory.taskName.ConfirmPayTransaction, data.purpose.typeOf, data.purpose.orderNumber, factory_1.factory.assetTransactionType.Pay, invoice.paymentMethodId);
|
|
55
55
|
const confirmPayTransactionTask = {
|
|
56
|
-
alternateName: taskIdentifier,
|
|
56
|
+
// alternateName: taskIdentifier,
|
|
57
57
|
identifier: taskIdentifier,
|
|
58
58
|
project: order.project,
|
|
59
59
|
name: factory_1.factory.taskName.ConfirmPayTransaction,
|
|
@@ -48,7 +48,7 @@ function createSendEmailMessageTaskIfNotExist(params) {
|
|
|
48
48
|
purpose: simpleOrder
|
|
49
49
|
};
|
|
50
50
|
const sendEmailMessageTask = {
|
|
51
|
-
alternateName: taskIdentifier,
|
|
51
|
+
// alternateName: taskIdentifier,
|
|
52
52
|
identifier: taskIdentifier,
|
|
53
53
|
project: params.order.project,
|
|
54
54
|
name: factory_1.factory.taskName.SendEmailMessage,
|
|
@@ -6,7 +6,7 @@ type IProcessingOrder = Pick<factory.order.IOrder, 'id' | 'orderNumber' | 'broke
|
|
|
6
6
|
orderStatus: factory.orderStatus.OrderProcessing;
|
|
7
7
|
};
|
|
8
8
|
type ICreatingCheckResourceTask = Pick<factory.task.checkResource.IAttributes, 'alternateName' | 'data' | 'executionResults' | 'identifier' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'> & {
|
|
9
|
-
alternateName
|
|
9
|
+
alternateName?: never;
|
|
10
10
|
identifier: string;
|
|
11
11
|
};
|
|
12
12
|
type ICreatingInformProcessingOrderTask = Pick<factory.task.IAttributes<factory.taskName.TriggerWebhook>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'>;
|
|
@@ -142,7 +142,7 @@ function createCheckResourceTask(order) {
|
|
|
142
142
|
};
|
|
143
143
|
const taskIdentifier = (0, util_1.format)('%s:%s:%s:%s', order.project.id, factory_1.factory.taskName.CheckResource, order.typeOf, order.orderNumber);
|
|
144
144
|
return {
|
|
145
|
-
alternateName: taskIdentifier, // add identifier(2025-03-29~)
|
|
145
|
+
// alternateName: taskIdentifier, // add identifier(2025-03-29~)
|
|
146
146
|
identifier: taskIdentifier, // add identifier(2025-03-29~)
|
|
147
147
|
project: order.project,
|
|
148
148
|
name: factory_1.factory.taskName.CheckResource,
|
|
@@ -50,7 +50,7 @@ function createConfirmReserveTransactionTasksIfNotExist(order, simpleOrder, opti
|
|
|
50
50
|
};
|
|
51
51
|
const taskIdentifier = (0, util_1.format)('%s:%s:%s:%s:%s:%s', order.project.id, factory_1.factory.taskName.ConfirmReserveTransaction, data.purpose.typeOf, data.purpose.orderNumber, data.object.typeOf, data.object.transactionNumber);
|
|
52
52
|
const confirmReserveTransactionTask = {
|
|
53
|
-
alternateName: taskIdentifier,
|
|
53
|
+
// alternateName: taskIdentifier,
|
|
54
54
|
identifier: taskIdentifier,
|
|
55
55
|
project: order.project,
|
|
56
56
|
name: factory_1.factory.taskName.ConfirmReserveTransaction,
|
|
@@ -18,7 +18,6 @@ import type { ProductRepo } from '../repo/product';
|
|
|
18
18
|
import type { ProjectRepo } from '../repo/project';
|
|
19
19
|
import type { ReservationRepo } from '../repo/reservation';
|
|
20
20
|
import type { SellerRepo } from '../repo/seller';
|
|
21
|
-
import type { TaskRepo } from '../repo/task';
|
|
22
21
|
export declare function deleteProject(params: {
|
|
23
22
|
id: string;
|
|
24
23
|
}): (repos: {
|
|
@@ -38,7 +37,6 @@ export declare function deleteProject(params: {
|
|
|
38
37
|
movieTheater: MovieTheaterRepo;
|
|
39
38
|
screeningRoom: ScreeningRoomRepo;
|
|
40
39
|
seller: SellerRepo;
|
|
41
|
-
task: TaskRepo;
|
|
42
40
|
assetTransaction: AssetTransactionRepo;
|
|
43
41
|
}) => Promise<void>;
|
|
44
42
|
export declare function cleanUpDatabaseByProject(params: {
|
|
@@ -59,5 +57,4 @@ export declare function cleanUpDatabaseByProject(params: {
|
|
|
59
57
|
movieTheater: MovieTheaterRepo;
|
|
60
58
|
screeningRoom: ScreeningRoomRepo;
|
|
61
59
|
seller: SellerRepo;
|
|
62
|
-
task: TaskRepo;
|
|
63
60
|
}) => Promise<void>;
|
|
@@ -26,6 +26,5 @@ function cleanUpDatabaseByProject(params) {
|
|
|
26
26
|
await repos.product.deleteByProject({ project: { id: params.id } });
|
|
27
27
|
await repos.reservation.deleteByProject({ project: { id: params.id } });
|
|
28
28
|
await repos.seller.deleteByProject({ project: { id: params.id } });
|
|
29
|
-
await repos.task.deleteByProject({ project: { id: params.id } });
|
|
30
29
|
};
|
|
31
30
|
}
|
|
@@ -42,7 +42,7 @@ function onReservationConfirmed(confirmedReservations, reserveAction) {
|
|
|
42
42
|
// );
|
|
43
43
|
const taskIdentifier = `${project.id}:${factory_1.factory.taskName.OnAuthorizationCreated}:${factory_1.factory.assetTransactionType.Reserve}:${reservationNumber}:onReservationConfirmed`;
|
|
44
44
|
onAuthorizationCreatedTask = {
|
|
45
|
-
alternateName: taskIdentifier,
|
|
45
|
+
// alternateName: taskIdentifier,
|
|
46
46
|
identifier: taskIdentifier,
|
|
47
47
|
name: factory_1.factory.taskName.OnAuthorizationCreated,
|
|
48
48
|
status: factory_1.factory.taskStatus.Ready,
|
|
@@ -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.
|
|
262
|
+
await repos.task.runTaskByIdentifier(onAssetTransactionStatusChangedTask);
|
|
261
263
|
}
|
|
262
264
|
};
|
|
263
265
|
}
|
package/package.json
CHANGED