@chevre/domain 21.33.0-alpha.10 → 21.33.0-alpha.11
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,37 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
function onTransactionStatusChangedListener() {
|
|
9
|
+
return async (params: {
|
|
10
|
+
/**
|
|
11
|
+
* 取引ID
|
|
12
|
+
*/
|
|
13
|
+
id: string;
|
|
14
|
+
typeOf: chevre.factory.transactionType;
|
|
15
|
+
status: chevre.factory.transactionStatusType;
|
|
16
|
+
}) => {
|
|
17
|
+
const { id, typeOf, status } = params;
|
|
18
|
+
console.log('transactionStatusChanged.', id, typeOf, status);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
chevre.eventEmitter.transaction.onTransactionStatusChanged(onTransactionStatusChangedListener());
|
|
23
|
+
|
|
24
|
+
async function main() {
|
|
25
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
26
|
+
|
|
27
|
+
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
28
|
+
|
|
29
|
+
const result = await transactionRepo.reexportTasksByExportAction({
|
|
30
|
+
intervalInMinutes: 10
|
|
31
|
+
});
|
|
32
|
+
console.log('reexported', result);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
main()
|
|
36
|
+
.then()
|
|
37
|
+
.catch(console.error);
|
|
@@ -158,9 +158,12 @@ export declare class MongoRepository {
|
|
|
158
158
|
}): Promise<Pick<factory.transaction.ITransaction<T>, 'id' | 'typeOf'> | null>;
|
|
159
159
|
/**
|
|
160
160
|
* タスクエクスポートリトライ
|
|
161
|
-
*
|
|
161
|
+
* @deprecated use reexportTasksByExportAction
|
|
162
162
|
*/
|
|
163
|
-
|
|
163
|
+
reexportTasksByExportationStatus(params: {
|
|
164
|
+
intervalInMinutes: number;
|
|
165
|
+
}): Promise<void>;
|
|
166
|
+
reexportTasksByExportAction(params: {
|
|
164
167
|
intervalInMinutes: number;
|
|
165
168
|
}): Promise<void>;
|
|
166
169
|
/**
|
|
@@ -548,12 +548,11 @@ class MongoRepository {
|
|
|
548
548
|
.then((doc) => (doc === null) ? null : doc.toObject());
|
|
549
549
|
});
|
|
550
550
|
}
|
|
551
|
-
// tslint:disable-next-line:no-suspicious-comment
|
|
552
551
|
/**
|
|
553
552
|
* タスクエクスポートリトライ
|
|
554
|
-
*
|
|
553
|
+
* @deprecated use reexportTasksByExportAction
|
|
555
554
|
*/
|
|
556
|
-
|
|
555
|
+
reexportTasksByExportationStatus(params) {
|
|
557
556
|
return __awaiter(this, void 0, void 0, function* () {
|
|
558
557
|
const reexportingTransactions = yield this.transactionModel.find({
|
|
559
558
|
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
|
|
@@ -591,6 +590,46 @@ class MongoRepository {
|
|
|
591
590
|
}
|
|
592
591
|
});
|
|
593
592
|
}
|
|
593
|
+
reexportTasksByExportAction(params) {
|
|
594
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
595
|
+
const reexportingTransactions = yield this.transactionModel.find({
|
|
596
|
+
'tasksExportAction.actionStatus': {
|
|
597
|
+
$exists: true,
|
|
598
|
+
$eq: factory.actionStatusType.ActiveActionStatus
|
|
599
|
+
},
|
|
600
|
+
'tasksExportAction.startDate': {
|
|
601
|
+
$exists: true,
|
|
602
|
+
$lt: moment()
|
|
603
|
+
.add(-params.intervalInMinutes, 'minutes')
|
|
604
|
+
.toDate()
|
|
605
|
+
}
|
|
606
|
+
}, { _id: 1, typeOf: 1, status: 1 })
|
|
607
|
+
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
608
|
+
.exec();
|
|
609
|
+
if (reexportingTransactions.length > 0) {
|
|
610
|
+
for (const reexportingTransaction of reexportingTransactions) {
|
|
611
|
+
yield this.transactionModel.updateOne({
|
|
612
|
+
_id: { $eq: reexportingTransaction.id },
|
|
613
|
+
'tasksExportAction.actionStatus': {
|
|
614
|
+
$exists: true,
|
|
615
|
+
$eq: factory.actionStatusType.ActiveActionStatus
|
|
616
|
+
}
|
|
617
|
+
}, {
|
|
618
|
+
tasksExportAction: {
|
|
619
|
+
actionStatus: factory.actionStatusType.PotentialActionStatus
|
|
620
|
+
},
|
|
621
|
+
tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
622
|
+
})
|
|
623
|
+
.exec();
|
|
624
|
+
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
|
|
625
|
+
id: reexportingTransaction.id,
|
|
626
|
+
typeOf: reexportingTransaction.typeOf,
|
|
627
|
+
status: reexportingTransaction.status
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
}
|
|
594
633
|
/**
|
|
595
634
|
* タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
|
|
596
635
|
*/
|
package/package.json
CHANGED