@chevre/domain 22.9.0-alpha.50 → 22.9.0-alpha.52

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,27 @@
1
+ // tslint:disable:no-implicit-dependencies no-console
2
+ import { chevre } from '../../../lib/index';
3
+
4
+ import * as moment from 'moment';
5
+ import * as mongoose from 'mongoose';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
13
+
14
+ const expiresLt = moment()
15
+ .add(-1, 'hour')
16
+ .toDate();
17
+ const result = await taskRepo.makeExpiredMany({
18
+ expiresLt
19
+ });
20
+ console.log('result:', result);
21
+ }
22
+
23
+ main()
24
+ .then(() => {
25
+ console.log('success!');
26
+ })
27
+ .catch(console.error);
@@ -94,6 +94,15 @@ const indexes = [
94
94
  }
95
95
  }
96
96
  ],
97
+ [
98
+ { expires: 1, runsAt: -1 },
99
+ {
100
+ name: 'expires',
101
+ partialFilterExpression: {
102
+ expires: { $exists: true }
103
+ }
104
+ }
105
+ ],
97
106
  [
98
107
  { remainingNumberOfTries: 1, runsAt: -1 },
99
108
  { name: 'searchByRemainingNumberOfTries-v2' }
@@ -78,9 +78,9 @@ export declare class TaskRepo {
78
78
  };
79
79
  }): Promise<IExecutableTask<T> | null>;
80
80
  /**
81
- * 一定期間遅延したタスクを実行する
81
+ * emit OnTaskStatusChanged on delayed tasks
82
82
  */
83
- executeTasks(params: {
83
+ emitDelayedTasksEvent(params: {
84
84
  now: Date;
85
85
  /**
86
86
  * 指定期間遅延しているタスクを実行する
@@ -98,6 +98,12 @@ export declare class TaskRepo {
98
98
  $nin?: factory.taskName[];
99
99
  };
100
100
  }): Promise<IDelayedTask[]>;
101
+ /**
102
+ * make tasks expired
103
+ */
104
+ makeExpiredMany(params: {
105
+ expiresLt: Date;
106
+ }): Promise<UpdateWriteOpResult>;
101
107
  /**
102
108
  * 実行中ステータスのままになっているタスクをリトライする
103
109
  */
@@ -436,9 +436,9 @@ class TaskRepo {
436
436
  });
437
437
  }
438
438
  /**
439
- * 一定期間遅延したタスクを実行する
439
+ * emit OnTaskStatusChanged on delayed tasks
440
440
  */
441
- executeTasks(params) {
441
+ emitDelayedTasksEvent(params) {
442
442
  return __awaiter(this, void 0, void 0, function* () {
443
443
  const runsAtLt = moment(params.now)
444
444
  .add(-params.delayInSeconds, 'seconds')
@@ -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();
@@ -471,6 +467,26 @@ class TaskRepo {
471
467
  return delayedTasks;
472
468
  });
473
469
  }
470
+ /**
471
+ * make tasks expired
472
+ */
473
+ makeExpiredMany(params) {
474
+ return __awaiter(this, void 0, void 0, function* () {
475
+ const { expiresLt } = params;
476
+ if (!(expiresLt instanceof Date)) {
477
+ throw new factory.errors.Argument('expiresLt', 'must be Date');
478
+ }
479
+ return this.taskModel.updateMany({
480
+ status: { $eq: factory.taskStatus.Ready },
481
+ expires: { $exists: true, $lt: expiresLt }
482
+ }, {
483
+ $set: {
484
+ status: factory.taskStatus.Expired
485
+ }
486
+ })
487
+ .exec();
488
+ });
489
+ }
474
490
  /**
475
491
  * 実行中ステータスのままになっているタスクをリトライする
476
492
  */
@@ -701,6 +701,9 @@ class TransactionRepo {
701
701
  if (typeof params.limit !== 'number' || params.limit === 0) {
702
702
  throw new factory.errors.ArgumentNull('limit');
703
703
  }
704
+ const sort = {
705
+ startDate: factory.sortType.Ascending
706
+ };
704
707
  // IDをemitしたいのでまずリスト検索(2023-04-27~)
705
708
  const expiringTransactions = yield this.transactionModel.find({
706
709
  status: { $eq: factory.transactionStatusType.InProgress },
@@ -712,6 +715,7 @@ class TransactionRepo {
712
715
  typeOf: 1
713
716
  })
714
717
  .limit(params.limit)
718
+ .sort(sort) // sort(2025-03-03~)
715
719
  .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
716
720
  .lean()
717
721
  .exec();
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "4.393.0-alpha.35",
14
+ "@chevre/factory": "4.393.0-alpha.36",
15
15
  "@cinerino/sdk": "10.21.0-alpha.23",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.3.0",
@@ -112,5 +112,5 @@
112
112
  "postversion": "git push origin --tags",
113
113
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
114
114
  },
115
- "version": "22.9.0-alpha.50"
115
+ "version": "22.9.0-alpha.52"
116
116
  }
@@ -1,41 +0,0 @@
1
- // tslint:disable:no-implicit-dependencies no-console
2
- import { chevre } from '../../../lib/index';
3
-
4
- import * as moment from 'moment';
5
- import * as mongoose from 'mongoose';
6
-
7
- const project = { id: String(process.env.PROJECT_ID) };
8
-
9
- async function main() {
10
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
-
12
- const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
13
- const result = await taskRepo.taskModel.updateMany(
14
- {
15
- // _id: { $eq: '673b5f8f5735a0a2dc953cfc' },
16
- 'project.id': { $eq: project.id },
17
- status: { $eq: chevre.factory.taskStatus.Aborted },
18
- lastTriedAt: {
19
- $gt: moment()
20
- // tslint:disable-next-line:no-magic-numbers
21
- .add(-2, 'days')
22
- .toDate()
23
- },
24
- name: { $eq: chevre.factory.taskName.VoidPayment }
25
- },
26
- {
27
- $set: {
28
- status: chevre.factory.taskStatus.Ready,
29
- remainingNumberOfTries: 3
30
- }
31
- }
32
- )
33
- .exec();
34
- console.log('result:', result);
35
- }
36
-
37
- main()
38
- .then(() => {
39
- console.log('success!');
40
- })
41
- .catch(console.error);