@chevre/domain 22.11.0-alpha.30 → 22.11.0-alpha.32

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,109 @@
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
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+ const MAX_LENGTH = 50;
9
+ const CHECK_DAYS = 60;
10
+
11
+ async function main() {
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
+
14
+ const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
15
+
16
+ const cursor = orderRepo.getCursor(
17
+ {
18
+ typeOf: { $eq: chevre.factory.order.OrderType.Order },
19
+ orderDate: {
20
+ $gte: moment()
21
+ .add(-CHECK_DAYS, 'days')
22
+ .toDate()
23
+ }
24
+ // _id: { $eq: '67de46777ec0510590b68922' }
25
+ },
26
+ {
27
+ customer: 1,
28
+ project: 1,
29
+ orderDate: 1
30
+ }
31
+ );
32
+ console.log('docs found');
33
+
34
+ let i = 0;
35
+ let exceededCount = 0;
36
+ await cursor.eachAsync(async (doc) => {
37
+ i += 1;
38
+ const order: Pick<
39
+ chevre.factory.order.IOrder,
40
+ 'customer' | 'project' | 'orderDate'
41
+ > = doc.toObject();
42
+
43
+ const attributesNames: (keyof chevre.factory.order.ICustomer)[] = [
44
+ 'address',
45
+ 'age',
46
+ 'email',
47
+ 'givenName',
48
+ 'familyName',
49
+ 'gender',
50
+ 'name',
51
+ 'url',
52
+ 'telephone'
53
+ ];
54
+
55
+ const maxLengthNotExceeded = attributesNames.every((attributesName) => {
56
+ const attributesValue = order.customer[attributesName];
57
+ if (attributesValue === undefined) {
58
+ return true;
59
+ }
60
+ if (typeof attributesValue !== 'string') {
61
+ throw new Error(`${attributesName}: ${attributesValue} must be string. ${order.project.id}`);
62
+ }
63
+
64
+ return attributesValue.length <= MAX_LENGTH;
65
+ });
66
+
67
+ if (maxLengthNotExceeded) {
68
+ // no op
69
+ process.stdout.write('-');
70
+ } else {
71
+ exceededCount += 1;
72
+ console.log('\n');
73
+ console.log('maxLengthExceeded.', order.project.id, order.customer, order.orderDate, i);
74
+ }
75
+ });
76
+
77
+ console.log('\n');
78
+ console.log(i, 'docs checked');
79
+ console.log(exceededCount, 'docs exceeded');
80
+
81
+ // let result: any;
82
+ // const attributesNames = [
83
+ // // 'customer.address',
84
+ // // 'customer.age',
85
+ // 'customer.email',
86
+ // 'customer.givenName',
87
+ // 'customer.familyName'
88
+ // // 'customer.gender',
89
+ // // 'customer.name',
90
+ // // 'customer.url',
91
+ // ];
92
+ // for (const attributesName of attributesNames) {
93
+ // console.log('how is', attributesName, '?');
94
+ // result = await orderRepo.checkCustomerAttributesLength({
95
+ // attributesName,
96
+ // length: MAX_LENGTH
97
+ // });
98
+ // // tslint:disable-next-line:no-null-keyword
99
+ // console.dir(result, { depth: null });
100
+ // console.log('how is', attributesName, '?', result.length, 'results found');
101
+ // }
102
+ }
103
+
104
+ main()
105
+ .then(() => {
106
+ console.log('\n');
107
+ console.log('success!');
108
+ })
109
+ .catch(console.error);
@@ -2,9 +2,10 @@
2
2
  import * as moment from 'moment';
3
3
  import * as mongoose from 'mongoose';
4
4
 
5
- import { chevre } from '../../../lib/index';
5
+ import { chevre } from '../../../../lib/index';
6
6
 
7
- const TASK_STORAGE_PERIOD_IN_MINUTES = 43200; // 30*24*60
7
+ // const TASK_STORAGE_PERIOD_IN_MINUTES = 43200; // 30*24*60
8
+ const TASK_STORAGE_PERIOD_IN_MINUTES = 28800; // 20*24*60
8
9
 
9
10
  async function main() {
10
11
  const now = new Date();
@@ -12,7 +13,7 @@ async function main() {
12
13
 
13
14
  const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
14
15
 
15
- let taskInMinutes = 57600; // 40*24*60
16
+ let taskInMinutes = 44640; // 31*24*60
16
17
  // let taskInMinutes = 172800; // 120*24*60
17
18
  // tslint:disable-next-line:no-magic-numbers
18
19
  while (taskInMinutes > TASK_STORAGE_PERIOD_IN_MINUTES) {
@@ -0,0 +1,23 @@
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 taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
10
+ const result = await taskRepo.taskModel.deleteMany({
11
+ $or: [
12
+ { name: { $exists: false } },
13
+ { status: { $exists: false } }
14
+ ]
15
+ })
16
+ .exec();
17
+
18
+ console.log('success!', result);
19
+ }
20
+
21
+ main()
22
+ .then()
23
+ .catch(console.error);
@@ -43,11 +43,11 @@ interface IRunningTaskByName {
43
43
  executionResult?: never;
44
44
  }
45
45
  /**
46
- * 実行後失敗したタスクイベント
46
+ * 実行後タスクイベント
47
47
  */
48
48
  interface IExecutedTask {
49
49
  id: string;
50
- status: factory.taskStatus.Running | factory.taskStatus.Aborted;
50
+ status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
51
51
  name: factory.taskName;
52
52
  executionResult: factory.task.IExecutionResult;
53
53
  /**
@@ -119,12 +119,15 @@ export declare class TaskRepo {
119
119
  * 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
120
120
  */
121
121
  emitRunningIfExists(params: {
122
- name?: {
123
- $eq?: factory.taskName;
124
- $in?: factory.taskName[];
125
- };
126
- executor: {
127
- name: string;
122
+ /**
123
+ * 必ずタスク名指定で実行する
124
+ */
125
+ name: {
126
+ $eq: factory.taskName;
127
+ $in?: never;
128
+ } | {
129
+ $eq?: never;
130
+ $in: factory.taskName[];
128
131
  };
129
132
  runsAt: {
130
133
  $lt: Date;
@@ -133,6 +136,10 @@ export declare class TaskRepo {
133
136
  numberOfTried?: factory.sortType;
134
137
  runsAt?: factory.sortType;
135
138
  };
139
+ executor: {
140
+ name: string;
141
+ };
142
+ nameFilterBeforeRunsAt: boolean;
136
143
  }, next?: INextFunction): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
137
144
  /**
138
145
  * Readyのままで期限切れのタスクをExpiredに変更する
@@ -460,7 +460,7 @@ class TaskRepo {
460
460
  emitRunningIfExists(params, next // support next function(2025-08-02~)
461
461
  ) {
462
462
  return __awaiter(this, void 0, void 0, function* () {
463
- var _a, _b;
463
+ var _a;
464
464
  if (!(params.runsAt.$lt instanceof Date)) {
465
465
  throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
466
466
  }
@@ -471,12 +471,20 @@ class TaskRepo {
471
471
  };
472
472
  const nameEq = (_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq;
473
473
  // const nameNin = params.name?.$nin;
474
- const nameIn = (_b = params.name) === null || _b === void 0 ? void 0 : _b.$in;
475
- const doc = yield this.taskModel.findOneAndUpdate(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: params.runsAt.$lt } }, (typeof nameEq === 'string' || Array.isArray(nameIn))
476
- ? {
477
- name: Object.assign(Object.assign({}, (typeof nameEq === 'string') ? { $eq: nameEq } : undefined), (Array.isArray(nameIn)) ? { $in: nameIn } : undefined)
478
- }
479
- : undefined), {
474
+ // const nameIn = params.name?.$in;
475
+ const { nameFilterBeforeRunsAt } = params;
476
+ const filter = Object.assign(Object.assign(Object.assign({ status: { $eq: factory.taskStatus.Ready } }, (nameFilterBeforeRunsAt) ? { name: params.name } : undefined), { runsAt: { $lt: params.runsAt.$lt } }), (!nameFilterBeforeRunsAt) ? { name: params.name } : undefined
477
+ // ...(typeof nameEq === 'string' || Array.isArray(nameIn))
478
+ // ? {
479
+ // name: {
480
+ // ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined,
481
+ // // ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
482
+ // ...(Array.isArray(nameIn)) ? { $in: nameIn } : undefined
483
+ // }
484
+ // }
485
+ // : undefined
486
+ );
487
+ const doc = yield this.taskModel.findOneAndUpdate(filter, {
480
488
  $set: {
481
489
  status: factory.taskStatus.Running, // 実行中に変更
482
490
  lastTriedAt: new Date(),
@@ -650,10 +658,8 @@ class TaskRepo {
650
658
  .exec();
651
659
  // emit event(2025-05-26~)
652
660
  if (typeof next === 'function') {
653
- if (status !== factory.taskStatus.Executed) {
654
- const changedTask = { id, name, status, remainingNumberOfTries, executionResult };
655
- task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
656
- }
661
+ const changedTask = { id, name, status, remainingNumberOfTries, executionResult };
662
+ task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
657
663
  }
658
664
  });
659
665
  }
package/package.json CHANGED
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "22.11.0-alpha.30"
118
+ "version": "22.11.0-alpha.32"
119
119
  }