@chevre/domain 21.2.0-alpha.16 → 21.2.0-alpha.18
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/example/src/chevre/transaction/makeExpired.ts +18 -0
- package/lib/chevre/eventEmitter/task.d.ts +3 -2
- package/lib/chevre/eventEmitter/transaction.d.ts +1 -1
- package/lib/chevre/repo/assetTransaction.js +20 -6
- package/lib/chevre/repo/task.js +8 -2
- package/lib/chevre/repo/transaction.js +27 -6
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
|
|
10
|
+
const result = await transactionRepo.makeExpired({
|
|
11
|
+
expires: new Date()
|
|
12
|
+
});
|
|
13
|
+
console.log(result);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
main()
|
|
17
|
+
.then(console.log)
|
|
18
|
+
.catch(console.error);
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import * as factory from '../factory';
|
|
4
4
|
interface IListenArgsOnTaskStatusChanged {
|
|
5
|
-
id
|
|
5
|
+
id?: string;
|
|
6
|
+
name: factory.taskName;
|
|
6
7
|
status: factory.taskStatus;
|
|
7
8
|
}
|
|
8
9
|
type IOnTaskStatusChangedListener = (listenArgs: IListenArgsOnTaskStatusChanged) => void;
|
|
@@ -14,4 +15,4 @@ declare class TaskEventEmitter extends EventEmitter {
|
|
|
14
15
|
emitTaskStatusChanged(args: IListenArgsOnTaskStatusChanged): void;
|
|
15
16
|
}
|
|
16
17
|
declare const taskEventEmitter: TaskEventEmitter;
|
|
17
|
-
export { taskEventEmitter };
|
|
18
|
+
export { IOnTaskStatusChangedListener, taskEventEmitter };
|
|
@@ -18,4 +18,4 @@ declare class TransactionEventEmitter extends EventEmitter {
|
|
|
18
18
|
emitTransactionStatusChanged(args: IListenArgsOnTransactionStatusChanged): void;
|
|
19
19
|
}
|
|
20
20
|
declare const transactionEventEmitter: TransactionEventEmitter;
|
|
21
|
-
export { transactionEventEmitter };
|
|
21
|
+
export { IListenArgsOnTransactionStatusChanged, transactionEventEmitter };
|
|
@@ -405,15 +405,29 @@ class MongoRepository {
|
|
|
405
405
|
*/
|
|
406
406
|
makeExpired(params) {
|
|
407
407
|
return __awaiter(this, void 0, void 0, function* () {
|
|
408
|
-
//
|
|
409
|
-
yield this.transactionModel.
|
|
410
|
-
status: factory.transactionStatusType.InProgress,
|
|
408
|
+
// IDをemitしたいのでまずリスト検索(2023-04-27~)
|
|
409
|
+
const expiringTransactions = yield this.transactionModel.find({
|
|
410
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
411
411
|
expires: { $lt: params.expires }
|
|
412
|
-
}, {
|
|
413
|
-
status: factory.transactionStatusType.Expired,
|
|
414
|
-
endDate: new Date()
|
|
415
412
|
})
|
|
413
|
+
.select({
|
|
414
|
+
_id: 1,
|
|
415
|
+
typeOf: 1
|
|
416
|
+
})
|
|
417
|
+
.setOptions({ maxTimeMS: 10000 })
|
|
416
418
|
.exec();
|
|
419
|
+
if (expiringTransactions.length > 0) {
|
|
420
|
+
// ステータスと期限を見て更新
|
|
421
|
+
yield this.transactionModel.updateMany({
|
|
422
|
+
_id: { $in: expiringTransactions.map((t) => t.id) },
|
|
423
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
424
|
+
expires: { $lt: params.expires }
|
|
425
|
+
}, {
|
|
426
|
+
status: factory.transactionStatusType.Expired,
|
|
427
|
+
endDate: new Date()
|
|
428
|
+
})
|
|
429
|
+
.exec();
|
|
430
|
+
}
|
|
417
431
|
});
|
|
418
432
|
}
|
|
419
433
|
/**
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -161,12 +161,18 @@ class MongoRepository {
|
|
|
161
161
|
.map((objectId) => {
|
|
162
162
|
return { id: objectId.toHexString() };
|
|
163
163
|
});
|
|
164
|
-
|
|
164
|
+
taskAttributes.forEach((savedTask) => {
|
|
165
165
|
task_2.taskEventEmitter.emitTaskStatusChanged({
|
|
166
|
-
|
|
166
|
+
name: savedTask.name,
|
|
167
167
|
status: factory.taskStatus.Ready
|
|
168
168
|
});
|
|
169
169
|
});
|
|
170
|
+
// savedTasks.forEach((savedTask) => {
|
|
171
|
+
// taskEventEmitter.emitTaskStatusChanged({
|
|
172
|
+
// id: savedTask.id,
|
|
173
|
+
// status: factory.taskStatus.Ready
|
|
174
|
+
// });
|
|
175
|
+
// });
|
|
170
176
|
// return result.ops;
|
|
171
177
|
return savedTasks;
|
|
172
178
|
}
|
|
@@ -509,15 +509,36 @@ class MongoRepository {
|
|
|
509
509
|
*/
|
|
510
510
|
makeExpired(params) {
|
|
511
511
|
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
-
//
|
|
513
|
-
yield this.transactionModel.
|
|
514
|
-
status: factory.transactionStatusType.InProgress,
|
|
512
|
+
// IDをemitしたいのでまずリスト検索(2023-04-27~)
|
|
513
|
+
const expiringTransactions = yield this.transactionModel.find({
|
|
514
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
515
515
|
expires: { $lt: params.expires }
|
|
516
|
-
}, {
|
|
517
|
-
status: factory.transactionStatusType.Expired,
|
|
518
|
-
endDate: new Date()
|
|
519
516
|
})
|
|
517
|
+
.select({
|
|
518
|
+
_id: 1,
|
|
519
|
+
typeOf: 1
|
|
520
|
+
})
|
|
521
|
+
.setOptions({ maxTimeMS: 10000 })
|
|
520
522
|
.exec();
|
|
523
|
+
if (expiringTransactions.length > 0) {
|
|
524
|
+
// ステータスと期限を見て更新
|
|
525
|
+
yield this.transactionModel.updateMany({
|
|
526
|
+
_id: { $in: expiringTransactions.map((t) => t.id) },
|
|
527
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
528
|
+
expires: { $lt: params.expires }
|
|
529
|
+
}, {
|
|
530
|
+
status: factory.transactionStatusType.Expired,
|
|
531
|
+
endDate: new Date()
|
|
532
|
+
})
|
|
533
|
+
.exec();
|
|
534
|
+
expiringTransactions.forEach((expiringTransaction) => {
|
|
535
|
+
transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
|
|
536
|
+
id: expiringTransaction.id,
|
|
537
|
+
typeOf: expiringTransaction.typeOf,
|
|
538
|
+
status: factory.transactionStatusType.Expired
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
}
|
|
521
542
|
});
|
|
522
543
|
}
|
|
523
544
|
/**
|
package/package.json
CHANGED