@chevre/domain 22.9.0-alpha.51 → 22.9.0-alpha.53
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.
|
@@ -11,14 +11,13 @@ async function main() {
|
|
|
11
11
|
|
|
12
12
|
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
13
13
|
|
|
14
|
-
const result = await transactionRepo.
|
|
14
|
+
const result = await transactionRepo.makeOneExpiredIfExists({
|
|
15
15
|
expires: {
|
|
16
16
|
$lt: moment()
|
|
17
17
|
// tslint:disable-next-line:no-magic-numbers
|
|
18
18
|
.add(-60, 'seconds')
|
|
19
19
|
.toDate()
|
|
20
|
-
}
|
|
21
|
-
limit: 1
|
|
20
|
+
}
|
|
22
21
|
});
|
|
23
22
|
|
|
24
23
|
console.log('result:', result);
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -450,12 +450,8 @@ class TaskRepo {
|
|
|
450
450
|
status: 1
|
|
451
451
|
};
|
|
452
452
|
const delayedTasks = yield this.taskModel.find(Object.assign(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: runsAtLt } }, (Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined), (Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined), projection)
|
|
453
|
-
// .select({
|
|
454
|
-
// _id: 1,
|
|
455
|
-
// name: 1,
|
|
456
|
-
// status: 1
|
|
457
|
-
// })
|
|
458
453
|
.limit(params.limit)
|
|
454
|
+
.sort(sortOrder4executionOfTasks) // sort(2025-03-03~)
|
|
459
455
|
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
460
456
|
.lean() // lean(2024-09-26~)
|
|
461
457
|
.exec();
|
|
@@ -142,6 +142,14 @@ export declare class TransactionRepo {
|
|
|
142
142
|
setTasksExportedById(params: {
|
|
143
143
|
id: string;
|
|
144
144
|
}): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* add(2025-03-03~)
|
|
147
|
+
*/
|
|
148
|
+
makeOneExpiredIfExists(params: {
|
|
149
|
+
expires: {
|
|
150
|
+
$lt: Date;
|
|
151
|
+
};
|
|
152
|
+
}): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'> | void>;
|
|
145
153
|
/**
|
|
146
154
|
* 取引を期限切れにする
|
|
147
155
|
*/
|
|
@@ -693,6 +693,41 @@ class TransactionRepo {
|
|
|
693
693
|
.exec();
|
|
694
694
|
});
|
|
695
695
|
}
|
|
696
|
+
/**
|
|
697
|
+
* add(2025-03-03~)
|
|
698
|
+
*/
|
|
699
|
+
makeOneExpiredIfExists(params) {
|
|
700
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
701
|
+
const endDate = new Date();
|
|
702
|
+
const doc = yield this.transactionModel.findOneAndUpdate({
|
|
703
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
704
|
+
expires: { $lt: params.expires.$lt }
|
|
705
|
+
}, {
|
|
706
|
+
status: factory.transactionStatusType.Expired,
|
|
707
|
+
endDate
|
|
708
|
+
}, {
|
|
709
|
+
new: true,
|
|
710
|
+
projection: {
|
|
711
|
+
_id: 0,
|
|
712
|
+
id: { $toString: '$_id' },
|
|
713
|
+
typeOf: 1
|
|
714
|
+
}
|
|
715
|
+
})
|
|
716
|
+
.lean()
|
|
717
|
+
.exec();
|
|
718
|
+
if (doc === null) {
|
|
719
|
+
// no op
|
|
720
|
+
}
|
|
721
|
+
else {
|
|
722
|
+
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
|
|
723
|
+
id: doc.id,
|
|
724
|
+
typeOf: doc.typeOf,
|
|
725
|
+
status: factory.transactionStatusType.Expired
|
|
726
|
+
});
|
|
727
|
+
return doc;
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
}
|
|
696
731
|
/**
|
|
697
732
|
* 取引を期限切れにする
|
|
698
733
|
*/
|
|
@@ -701,6 +736,9 @@ class TransactionRepo {
|
|
|
701
736
|
if (typeof params.limit !== 'number' || params.limit === 0) {
|
|
702
737
|
throw new factory.errors.ArgumentNull('limit');
|
|
703
738
|
}
|
|
739
|
+
const sort = {
|
|
740
|
+
startDate: factory.sortType.Ascending
|
|
741
|
+
};
|
|
704
742
|
// IDをemitしたいのでまずリスト検索(2023-04-27~)
|
|
705
743
|
const expiringTransactions = yield this.transactionModel.find({
|
|
706
744
|
status: { $eq: factory.transactionStatusType.InProgress },
|
|
@@ -712,6 +750,7 @@ class TransactionRepo {
|
|
|
712
750
|
typeOf: 1
|
|
713
751
|
})
|
|
714
752
|
.limit(params.limit)
|
|
753
|
+
.sort(sort) // sort(2025-03-03~)
|
|
715
754
|
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
716
755
|
.lean()
|
|
717
756
|
.exec();
|
package/package.json
CHANGED