@chevre/domain 22.11.0-alpha.28 → 22.11.0-alpha.29
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.
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// tslint:disable-next-line:max-func-body-length
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const aggregateDate = new Date();
|
|
14
|
+
const runsFrom: Date = moment(aggregateDate)
|
|
15
|
+
.utc()
|
|
16
|
+
// .tz('Asia/Tokyo')
|
|
17
|
+
.add(-1, 'days')
|
|
18
|
+
.startOf('days')
|
|
19
|
+
.toDate();
|
|
20
|
+
const runsThrough: Date = moment(aggregateDate)
|
|
21
|
+
.utc()
|
|
22
|
+
// .tz('Asia/Tokyo')
|
|
23
|
+
.add(-1, 'days')
|
|
24
|
+
.endOf('days')
|
|
25
|
+
.toDate();
|
|
26
|
+
|
|
27
|
+
const result = await taskRepo.aggregateTask({
|
|
28
|
+
project: {
|
|
29
|
+
id: { $ne: 'sskts-development' }
|
|
30
|
+
},
|
|
31
|
+
runsFrom,
|
|
32
|
+
runsThrough
|
|
33
|
+
});
|
|
34
|
+
console.dir(result, { depth: null });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
main()
|
|
38
|
+
.then(() => {
|
|
39
|
+
console.log('success!');
|
|
40
|
+
})
|
|
41
|
+
.catch(console.error);
|
|
@@ -25,7 +25,15 @@ async function main() {
|
|
|
25
25
|
}
|
|
26
26
|
}],
|
|
27
27
|
informTaskNames: [
|
|
28
|
-
chevre.factory.taskName.Pay
|
|
28
|
+
chevre.factory.taskName.Pay,
|
|
29
|
+
chevre.factory.taskName.InvalidatePaymentUrl,
|
|
30
|
+
chevre.factory.taskName.Refund,
|
|
31
|
+
chevre.factory.taskName.VoidPayment
|
|
32
|
+
// chevre.factory.taskName.ConfirmReserveTransaction
|
|
33
|
+
],
|
|
34
|
+
informTaskStatuses: [
|
|
35
|
+
chevre.factory.taskStatus.Aborted
|
|
36
|
+
// chevre.factory.taskStatus.Running
|
|
29
37
|
]
|
|
30
38
|
}
|
|
31
39
|
}
|
|
@@ -20,29 +20,43 @@ interface IReadyTask {
|
|
|
20
20
|
expires?: Date;
|
|
21
21
|
executionResult?: never;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* タスク名不明の遅延実行中タスク
|
|
25
|
+
*/
|
|
23
26
|
interface IRunningTask {
|
|
24
27
|
id: string;
|
|
25
28
|
status: factory.taskStatus.Running;
|
|
26
|
-
remainingNumberOfTries?: never;
|
|
27
29
|
name?: never;
|
|
30
|
+
remainingNumberOfTries?: never;
|
|
28
31
|
expires?: never;
|
|
29
32
|
executionResult?: never;
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
32
|
-
*
|
|
35
|
+
* タスク名指定での遅延実行中タスク
|
|
36
|
+
*/
|
|
37
|
+
interface IRunningTaskByName {
|
|
38
|
+
id: string;
|
|
39
|
+
status: factory.taskStatus.Running;
|
|
40
|
+
name: factory.taskName;
|
|
41
|
+
remainingNumberOfTries?: never;
|
|
42
|
+
expires?: never;
|
|
43
|
+
executionResult?: never;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 実行後失敗したタスクイベント
|
|
33
47
|
*/
|
|
34
48
|
interface IExecutedTask {
|
|
35
49
|
id: string;
|
|
36
|
-
status: factory.taskStatus.
|
|
50
|
+
status: factory.taskStatus.Running | factory.taskStatus.Aborted;
|
|
51
|
+
name: factory.taskName;
|
|
37
52
|
executionResult: factory.task.IExecutionResult;
|
|
38
53
|
/**
|
|
39
54
|
* 実行されたタスクの残り試行回数
|
|
40
55
|
*/
|
|
41
56
|
remainingNumberOfTries: number;
|
|
42
|
-
name: factory.taskName;
|
|
43
57
|
expires?: never;
|
|
44
58
|
}
|
|
45
|
-
type IChangedTask = IReadyTask | IRunningTask | IExecutedTask;
|
|
59
|
+
type IChangedTask = IReadyTask | IRunningTask | IRunningTaskByName | IExecutedTask;
|
|
46
60
|
type IOperationExecute<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
47
61
|
type INextFunction = (task: IExecutedTask) => IOperationExecute<void>;
|
|
48
62
|
type IOnTaskStatusChangedListener = (task: IChangedTask, next?: INextFunction) => void;
|
|
@@ -54,4 +68,4 @@ declare class TaskEventEmitter extends EventEmitter {
|
|
|
54
68
|
emitTaskStatusChanged(task: IChangedTask, next?: INextFunction): void;
|
|
55
69
|
}
|
|
56
70
|
declare const taskEventEmitter: TaskEventEmitter;
|
|
57
|
-
export { IChangedTask, IReadyTask, IRunningTask, IExecutedTask, IExecuteSettings, INextFunction, IOnTaskStatusChangedListener, taskEventEmitter };
|
|
71
|
+
export { IChangedTask, IReadyTask, IRunningTask, IRunningTaskByName, IExecutedTask, IExecuteSettings, INextFunction, IOnTaskStatusChangedListener, taskEventEmitter };
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -496,10 +496,21 @@ class TaskRepo {
|
|
|
496
496
|
// tslint:disable-next-line:no-null-keyword
|
|
497
497
|
return null;
|
|
498
498
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
499
|
+
let changedTask;
|
|
500
|
+
if (typeof nameEq === 'string') {
|
|
501
|
+
changedTask = {
|
|
502
|
+
id: doc.id,
|
|
503
|
+
status: factory.taskStatus.Running,
|
|
504
|
+
name: nameEq
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
changedTask = {
|
|
509
|
+
id: doc.id,
|
|
510
|
+
status: factory.taskStatus.Running
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, (typeof next === 'function') ? next : undefined);
|
|
503
514
|
return doc;
|
|
504
515
|
});
|
|
505
516
|
}
|
|
@@ -639,8 +650,10 @@ class TaskRepo {
|
|
|
639
650
|
.exec();
|
|
640
651
|
// emit event(2025-05-26~)
|
|
641
652
|
if (typeof next === 'function') {
|
|
642
|
-
|
|
643
|
-
|
|
653
|
+
if (status !== factory.taskStatus.Executed) {
|
|
654
|
+
const changedTask = { id, name, status, remainingNumberOfTries, executionResult };
|
|
655
|
+
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
|
|
656
|
+
}
|
|
644
657
|
}
|
|
645
658
|
});
|
|
646
659
|
}
|
|
@@ -762,10 +775,10 @@ class TaskRepo {
|
|
|
762
775
|
factory.taskStatus.Aborted
|
|
763
776
|
].map((taskStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
764
777
|
var _a, _b;
|
|
765
|
-
const matchConditions = Object.assign({ runsAt: {
|
|
778
|
+
const matchConditions = Object.assign({ status: { $eq: taskStatus }, runsAt: {
|
|
766
779
|
$gte: params.runsFrom,
|
|
767
780
|
$lte: params.runsThrough
|
|
768
|
-
}
|
|
781
|
+
} }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
|
|
769
782
|
? { 'project.id': { $ne: params.project.id.$ne } }
|
|
770
783
|
: undefined);
|
|
771
784
|
return this.agggregateByStatus({ matchConditions, status: taskStatus });
|
|
@@ -778,7 +791,7 @@ class TaskRepo {
|
|
|
778
791
|
return __awaiter(this, void 0, void 0, function* () {
|
|
779
792
|
const matchConditions = params.matchConditions;
|
|
780
793
|
const taskStatus = params.status;
|
|
781
|
-
const
|
|
794
|
+
const aggregate1 = this.taskModel.aggregate([
|
|
782
795
|
{
|
|
783
796
|
$match: matchConditions
|
|
784
797
|
},
|
|
@@ -808,8 +821,11 @@ class TaskRepo {
|
|
|
808
821
|
minLatency: '$minLatency'
|
|
809
822
|
}
|
|
810
823
|
}
|
|
811
|
-
])
|
|
812
|
-
|
|
824
|
+
]);
|
|
825
|
+
// const explainResult = await aggregate1.explain();
|
|
826
|
+
// console.dir(explainResult, { depth: null });
|
|
827
|
+
// return;
|
|
828
|
+
const aggregations = yield aggregate1.exec();
|
|
813
829
|
// tslint:disable-next-line:no-magic-numbers
|
|
814
830
|
const percents = [50, 95, 99];
|
|
815
831
|
if (aggregations.length === 0) {
|
|
@@ -836,7 +852,7 @@ class TaskRepo {
|
|
|
836
852
|
rank: Math.floor(aggregations[0].taskCount * percentile / 100)
|
|
837
853
|
};
|
|
838
854
|
});
|
|
839
|
-
const
|
|
855
|
+
const aggregate2 = this.taskModel.aggregate([
|
|
840
856
|
{
|
|
841
857
|
$match: matchConditions
|
|
842
858
|
},
|
|
@@ -866,8 +882,8 @@ class TaskRepo {
|
|
|
866
882
|
})
|
|
867
883
|
}
|
|
868
884
|
}
|
|
869
|
-
])
|
|
870
|
-
|
|
885
|
+
]);
|
|
886
|
+
const aggregations2 = yield aggregate2.exec();
|
|
871
887
|
return {
|
|
872
888
|
status: taskStatus,
|
|
873
889
|
aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
|
|
@@ -323,7 +323,7 @@ class TransactionRepo {
|
|
|
323
323
|
.lean() // 2024-08-26~
|
|
324
324
|
.exec();
|
|
325
325
|
if (doc === null) {
|
|
326
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
326
|
+
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} not found`);
|
|
327
327
|
}
|
|
328
328
|
return doc;
|
|
329
329
|
});
|
|
@@ -371,7 +371,7 @@ class TransactionRepo {
|
|
|
371
371
|
.lean() // 2024-08-26~
|
|
372
372
|
.exec();
|
|
373
373
|
if (doc === null) {
|
|
374
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
374
|
+
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
|
|
375
375
|
}
|
|
376
376
|
return doc;
|
|
377
377
|
});
|
|
@@ -389,7 +389,7 @@ class TransactionRepo {
|
|
|
389
389
|
.lean() // 2024-08-26~
|
|
390
390
|
.exec();
|
|
391
391
|
if (doc === null) {
|
|
392
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
392
|
+
throw new factory.errors.NotFound(this.transactionModel.modelName, `${factory.transactionType.PlaceOrder} ${factory.transactionStatusType.InProgress} not found`);
|
|
393
393
|
}
|
|
394
394
|
return doc.object.paymentMethods;
|
|
395
395
|
});
|
|
@@ -407,7 +407,7 @@ class TransactionRepo {
|
|
|
407
407
|
.lean() // 2024-08-26~
|
|
408
408
|
.exec();
|
|
409
409
|
if (doc === null) {
|
|
410
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
410
|
+
throw new factory.errors.NotFound(this.transactionModel.modelName, `${factory.transactionType.PlaceOrder} ${factory.transactionStatusType.InProgress} not found`);
|
|
411
411
|
}
|
|
412
412
|
return doc.object.orderNumber;
|
|
413
413
|
});
|
|
@@ -425,7 +425,7 @@ class TransactionRepo {
|
|
|
425
425
|
.lean() // 2024-08-26~
|
|
426
426
|
.exec();
|
|
427
427
|
if (doc === null) {
|
|
428
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
428
|
+
throw new factory.errors.NotFound(this.transactionModel.modelName, `${factory.transactionType.PlaceOrder} ${params.status.$in.join(' or ')} not found`);
|
|
429
429
|
}
|
|
430
430
|
return doc.object.confirmationNumber;
|
|
431
431
|
});
|
|
@@ -448,7 +448,7 @@ class TransactionRepo {
|
|
|
448
448
|
.lean()
|
|
449
449
|
.exec();
|
|
450
450
|
if (doc === null) {
|
|
451
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
451
|
+
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
|
|
452
452
|
}
|
|
453
453
|
});
|
|
454
454
|
}
|
|
@@ -471,7 +471,7 @@ class TransactionRepo {
|
|
|
471
471
|
.lean()
|
|
472
472
|
.exec();
|
|
473
473
|
if (doc === null) {
|
|
474
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
474
|
+
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
|
|
475
475
|
}
|
|
476
476
|
});
|
|
477
477
|
}
|
|
@@ -494,7 +494,7 @@ class TransactionRepo {
|
|
|
494
494
|
.lean()
|
|
495
495
|
.exec();
|
|
496
496
|
if (doc === null) {
|
|
497
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
497
|
+
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
|
|
498
498
|
}
|
|
499
499
|
});
|
|
500
500
|
}
|
|
@@ -538,7 +538,7 @@ class TransactionRepo {
|
|
|
538
538
|
.isSameOrBefore(moment(endDate))) {
|
|
539
539
|
throw new factory.errors.Argument('Transaction id', 'potentially expired');
|
|
540
540
|
}
|
|
541
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
541
|
+
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
|
|
542
542
|
}
|
|
543
543
|
}
|
|
544
544
|
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
|
|
@@ -914,7 +914,7 @@ class TransactionRepo {
|
|
|
914
914
|
throw new factory.errors.Argument('Transaction id', 'Confirmed transaction unable to cancel');
|
|
915
915
|
}
|
|
916
916
|
else {
|
|
917
|
-
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
917
|
+
throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
|
|
918
918
|
}
|
|
919
919
|
}
|
|
920
920
|
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
|
package/package.json
CHANGED