@chevre/domain 22.4.0-alpha.2 → 22.4.0-alpha.4
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/cancelEvent.ts +22 -0
- package/example/src/chevre/projectFields.ts +2 -2
- package/lib/chevre/repo/action.js +3 -3
- package/lib/chevre/repo/event.d.ts +1 -1
- package/lib/chevre/repo/event.js +3 -24
- package/lib/chevre/repo/task.d.ts +3 -12
- package/lib/chevre/repo/task.js +120 -129
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +2 -5
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +7 -5
- package/lib/chevre/service/payment/any.js +6 -15
- package/lib/chevre/service/task.js +2 -2
- package/package.json +1 -1
- package/example/src/chevre/searchTasks.ts +0 -43
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
+
|
|
11
|
+
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const result = await eventRepo.cancelEvent({
|
|
14
|
+
project: { id: project.id },
|
|
15
|
+
id: '7iri6w0m1h1hu5y'
|
|
16
|
+
});
|
|
17
|
+
console.log(result);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
main()
|
|
21
|
+
.then()
|
|
22
|
+
.catch(console.error);
|
|
@@ -8,7 +8,7 @@ const project = { id: String(process.env.PROJECT_ID) };
|
|
|
8
8
|
async function main() {
|
|
9
9
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
10
|
|
|
11
|
-
const repo = await chevre.repository.
|
|
11
|
+
const repo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
12
12
|
|
|
13
13
|
const docs = await repo.projectFields(
|
|
14
14
|
{
|
|
@@ -16,7 +16,7 @@ async function main() {
|
|
|
16
16
|
page: 1,
|
|
17
17
|
project: { id: { $eq: project.id } }
|
|
18
18
|
},
|
|
19
|
-
['id', 'identifier', '
|
|
19
|
+
['id', 'identifier', 'data']
|
|
20
20
|
);
|
|
21
21
|
// tslint:disable-next-line:no-null-keyword
|
|
22
22
|
console.dir(docs, { depth: null });
|
|
@@ -1179,7 +1179,7 @@ class ActionRepo {
|
|
|
1179
1179
|
};
|
|
1180
1180
|
const options = {
|
|
1181
1181
|
upsert: true,
|
|
1182
|
-
|
|
1182
|
+
includeResultMetadata: true
|
|
1183
1183
|
};
|
|
1184
1184
|
return this.actionRecipeModel.updateOne(filter, update, options)
|
|
1185
1185
|
.exec();
|
|
@@ -1204,7 +1204,7 @@ class ActionRepo {
|
|
|
1204
1204
|
};
|
|
1205
1205
|
const options = {
|
|
1206
1206
|
upsert: true,
|
|
1207
|
-
|
|
1207
|
+
includeResultMetadata: true
|
|
1208
1208
|
};
|
|
1209
1209
|
return this.actionModel.updateOne(filter, update, options)
|
|
1210
1210
|
.exec();
|
|
@@ -1535,7 +1535,7 @@ class ActionRepo {
|
|
|
1535
1535
|
};
|
|
1536
1536
|
const options = {
|
|
1537
1537
|
upsert: true,
|
|
1538
|
-
|
|
1538
|
+
includeResultMetadata: true
|
|
1539
1539
|
};
|
|
1540
1540
|
return this.actionRecipeModel.updateOne(filter, update, options)
|
|
1541
1541
|
.exec();
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -753,10 +753,10 @@ class EventRepo {
|
|
|
753
753
|
*/
|
|
754
754
|
cancelEvent(params) {
|
|
755
755
|
return __awaiter(this, void 0, void 0, function* () {
|
|
756
|
-
|
|
756
|
+
return this.eventModel.updateOne({
|
|
757
757
|
_id: { $eq: params.id },
|
|
758
758
|
'project.id': { $eq: params.project.id }
|
|
759
|
-
}, { $set: { eventStatus: factory.eventStatusType.EventCancelled } }, {
|
|
759
|
+
}, { $set: { eventStatus: factory.eventStatusType.EventCancelled } }, { includeResultMetadata: true })
|
|
760
760
|
.exec();
|
|
761
761
|
});
|
|
762
762
|
}
|
|
@@ -922,31 +922,10 @@ class EventRepo {
|
|
|
922
922
|
$push: {
|
|
923
923
|
'offers.seller.makesOffer': params.offers.seller.makesOffer
|
|
924
924
|
}
|
|
925
|
-
}, {
|
|
925
|
+
}, { includeResultMetadata: true })
|
|
926
926
|
.exec();
|
|
927
927
|
});
|
|
928
928
|
}
|
|
929
|
-
// public async deleteAvailableAtOrFrom(params: {
|
|
930
|
-
// id: string;
|
|
931
|
-
// offers: {
|
|
932
|
-
// seller: {
|
|
933
|
-
// makesOffer: { availableAtOrFrom: { id: string } };
|
|
934
|
-
// };
|
|
935
|
-
// };
|
|
936
|
-
// }): Promise<void> {
|
|
937
|
-
// await this.eventModel.updateOne(
|
|
938
|
-
// { _id: { $eq: params.id } },
|
|
939
|
-
// {
|
|
940
|
-
// $pull: {
|
|
941
|
-
// 'offers.seller.makesOffer': {
|
|
942
|
-
// 'availableAtOrFrom.id': { $eq: params.offers.seller.makesOffer.availableAtOrFrom.id }
|
|
943
|
-
// }
|
|
944
|
-
// }
|
|
945
|
-
// },
|
|
946
|
-
// { rawResult: true }
|
|
947
|
-
// )
|
|
948
|
-
// .exec();
|
|
949
|
-
// }
|
|
950
929
|
unsetUnnecessaryFields(params) {
|
|
951
930
|
return __awaiter(this, void 0, void 0, function* () {
|
|
952
931
|
return this.eventModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
@@ -48,10 +48,7 @@ interface IOptionOnCreate {
|
|
|
48
48
|
export type IExecutableTaskKeys = 'data' | 'id' | 'name' | 'status' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'expires';
|
|
49
49
|
export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys>;
|
|
50
50
|
type IDelayedTask = Pick<factory.task.ITask<factory.taskName>, 'id' | 'name' | 'status'>;
|
|
51
|
-
type IKeyOfProjection = keyof factory.task.ITask<factory.taskName
|
|
52
|
-
type IProjection = {
|
|
53
|
-
[key in IKeyOfProjection]?: 0 | 1;
|
|
54
|
-
};
|
|
51
|
+
type IKeyOfProjection = keyof factory.task.ITask<factory.taskName>;
|
|
55
52
|
/**
|
|
56
53
|
* タスクリポジトリ
|
|
57
54
|
*/
|
|
@@ -120,9 +117,7 @@ export declare class TaskRepo {
|
|
|
120
117
|
*/
|
|
121
118
|
$nin?: factory.taskName[];
|
|
122
119
|
};
|
|
123
|
-
}): Promise<
|
|
124
|
-
_id: import("mongoose").Types.ObjectId;
|
|
125
|
-
})[]>;
|
|
120
|
+
}): Promise<IDelayedTask[]>;
|
|
126
121
|
/**
|
|
127
122
|
* 実行中ステータスのままになっているタスクをリトライする
|
|
128
123
|
*/
|
|
@@ -154,15 +149,11 @@ export declare class TaskRepo {
|
|
|
154
149
|
/**
|
|
155
150
|
* 特定タスク検索
|
|
156
151
|
*/
|
|
157
|
-
findById<T extends factory.taskName>(params: {
|
|
158
|
-
name: T;
|
|
159
|
-
id: string;
|
|
160
|
-
}): Promise<factory.task.ITask<T>>;
|
|
161
152
|
count(params: factory.task.ISearchConditions): Promise<number>;
|
|
162
153
|
/**
|
|
163
154
|
* 検索する
|
|
164
155
|
*/
|
|
165
|
-
|
|
156
|
+
projectFields(params: factory.task.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.task.ITask<factory.taskName>[]>;
|
|
166
157
|
deleteByProject(params: {
|
|
167
158
|
project: {
|
|
168
159
|
id: string;
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -11,10 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.TaskRepo = void 0;
|
|
13
13
|
const moment = require("moment");
|
|
14
|
+
const task_1 = require("../eventEmitter/task");
|
|
14
15
|
const factory = require("../factory");
|
|
15
|
-
const task_1 = require("./mongoose/schemas/task");
|
|
16
|
-
const task_2 = require("../eventEmitter/task");
|
|
17
16
|
const settings_1 = require("../settings");
|
|
17
|
+
const task_2 = require("./mongoose/schemas/task");
|
|
18
18
|
/**
|
|
19
19
|
* タスク実行時のソート条件
|
|
20
20
|
*/
|
|
@@ -22,12 +22,28 @@ const sortOrder4executionOfTasks = {
|
|
|
22
22
|
numberOfTried: factory.sortType.Ascending,
|
|
23
23
|
runsAt: factory.sortType.Ascending // 実行予定日時の早さ優先
|
|
24
24
|
};
|
|
25
|
+
// type IProjection = { [key in IKeyOfProjection]?: 0 | 1; };
|
|
26
|
+
const AVAILABLE_PROJECT_FIELDS = [
|
|
27
|
+
'identifier',
|
|
28
|
+
'project',
|
|
29
|
+
'name',
|
|
30
|
+
'status',
|
|
31
|
+
'runsAt',
|
|
32
|
+
'remainingNumberOfTries',
|
|
33
|
+
'lastTriedAt',
|
|
34
|
+
'numberOfTried',
|
|
35
|
+
'executionResults',
|
|
36
|
+
'executor',
|
|
37
|
+
'data',
|
|
38
|
+
'dateAborted',
|
|
39
|
+
'expires'
|
|
40
|
+
];
|
|
25
41
|
/**
|
|
26
42
|
* タスクリポジトリ
|
|
27
43
|
*/
|
|
28
44
|
class TaskRepo {
|
|
29
45
|
constructor(connection) {
|
|
30
|
-
this.taskModel = connection.model(
|
|
46
|
+
this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
|
|
31
47
|
}
|
|
32
48
|
// tslint:disable-next-line:max-func-body-length
|
|
33
49
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
@@ -150,7 +166,7 @@ class TaskRepo {
|
|
|
150
166
|
}
|
|
151
167
|
const { emitImmediately } = options;
|
|
152
168
|
if (emitImmediately) {
|
|
153
|
-
|
|
169
|
+
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
154
170
|
id,
|
|
155
171
|
status: factory.taskStatus.Ready
|
|
156
172
|
});
|
|
@@ -172,7 +188,7 @@ class TaskRepo {
|
|
|
172
188
|
});
|
|
173
189
|
if (emitImmediately) {
|
|
174
190
|
savedTasks.forEach((savedTask) => {
|
|
175
|
-
|
|
191
|
+
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
176
192
|
id: savedTask.id,
|
|
177
193
|
status: factory.taskStatus.Ready
|
|
178
194
|
});
|
|
@@ -197,16 +213,22 @@ class TaskRepo {
|
|
|
197
213
|
*/
|
|
198
214
|
findByIdentifier(params) {
|
|
199
215
|
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
const projection = {
|
|
217
|
+
_id: 0,
|
|
218
|
+
id: { $toString: '$_id' },
|
|
219
|
+
status: 1
|
|
220
|
+
};
|
|
200
221
|
const doc = yield this.taskModel.findOne({
|
|
201
222
|
'project.id': { $eq: params.project.id },
|
|
202
223
|
name: { $eq: params.name },
|
|
203
224
|
identifier: { $exists: true, $eq: params.identifier }
|
|
204
|
-
},
|
|
225
|
+
}, projection)
|
|
226
|
+
.lean() // lean(2024-09-26~)
|
|
205
227
|
.exec();
|
|
206
228
|
if (doc === null) {
|
|
207
229
|
return;
|
|
208
230
|
}
|
|
209
|
-
const { id, status } = doc
|
|
231
|
+
const { id, status } = doc;
|
|
210
232
|
return { id, status };
|
|
211
233
|
});
|
|
212
234
|
}
|
|
@@ -226,7 +248,7 @@ class TaskRepo {
|
|
|
226
248
|
.select({ _id: 1 })
|
|
227
249
|
.exec();
|
|
228
250
|
if (options.emitImmediately) {
|
|
229
|
-
|
|
251
|
+
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
230
252
|
id: createdTask.id,
|
|
231
253
|
name: params.name,
|
|
232
254
|
status: factory.taskStatus.Ready
|
|
@@ -247,7 +269,7 @@ class TaskRepo {
|
|
|
247
269
|
.select({ _id: 1 })
|
|
248
270
|
.exec();
|
|
249
271
|
if (options.emitImmediately) {
|
|
250
|
-
|
|
272
|
+
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
251
273
|
id: createdTask.id,
|
|
252
274
|
name: params.name,
|
|
253
275
|
status: factory.taskStatus.Ready
|
|
@@ -271,7 +293,7 @@ class TaskRepo {
|
|
|
271
293
|
.select({ _id: 1 })
|
|
272
294
|
.exec();
|
|
273
295
|
if (options.emitImmediately) {
|
|
274
|
-
|
|
296
|
+
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
275
297
|
id: createdTask.id,
|
|
276
298
|
name: params.name,
|
|
277
299
|
status: factory.taskStatus.Ready
|
|
@@ -326,7 +348,7 @@ class TaskRepo {
|
|
|
326
348
|
.select({ _id: 1 })
|
|
327
349
|
.exec();
|
|
328
350
|
if (options.emitImmediately) {
|
|
329
|
-
|
|
351
|
+
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
330
352
|
id: createdTask.id,
|
|
331
353
|
name: params.name,
|
|
332
354
|
status: factory.taskStatus.Ready
|
|
@@ -334,60 +356,21 @@ class TaskRepo {
|
|
|
334
356
|
}
|
|
335
357
|
});
|
|
336
358
|
}
|
|
337
|
-
// public async createSendOrderTaskIfNotExist(
|
|
338
|
-
// params: factory.task.IAttributes<factory.taskName.SendOrder>,
|
|
339
|
-
// options: IOptionOnCreate
|
|
340
|
-
// ): Promise<void> {
|
|
341
|
-
// const createdTask = await this.taskModel.findOneAndUpdate(
|
|
342
|
-
// {
|
|
343
|
-
// 'project.id': { $eq: params.project.id },
|
|
344
|
-
// name: { $eq: params.name },
|
|
345
|
-
// 'data.object.orderNumber': {
|
|
346
|
-
// $exists: true,
|
|
347
|
-
// $eq: String(params.data.object.orderNumber)
|
|
348
|
-
// }
|
|
349
|
-
// },
|
|
350
|
-
// { $setOnInsert: params },
|
|
351
|
-
// { new: true, upsert: true }
|
|
352
|
-
// )
|
|
353
|
-
// .select({ _id: 1 })
|
|
354
|
-
// .exec();
|
|
355
|
-
// if (options.emitImmediately) {
|
|
356
|
-
// taskEventEmitter.emitTaskStatusChanged({
|
|
357
|
-
// id: createdTask.id,
|
|
358
|
-
// name: params.name,
|
|
359
|
-
// status: factory.taskStatus.Ready
|
|
360
|
-
// });
|
|
361
|
-
// }
|
|
362
|
-
// }
|
|
363
|
-
// public async createOnOrderPaymentCompletedTaskIfNotExist(
|
|
364
|
-
// params: factory.task.IAttributes<factory.taskName.OnOrderPaymentCompleted>,
|
|
365
|
-
// options: IOptionOnCreate
|
|
366
|
-
// ): Promise<void> {
|
|
367
|
-
// const createdTask = await this.taskModel.findOneAndUpdate(
|
|
368
|
-
// {
|
|
369
|
-
// 'project.id': { $eq: params.project.id },
|
|
370
|
-
// name: { $eq: params.name },
|
|
371
|
-
// 'data.object.orderNumber': {
|
|
372
|
-
// $exists: true,
|
|
373
|
-
// $eq: String(params.data.object.orderNumber)
|
|
374
|
-
// }
|
|
375
|
-
// },
|
|
376
|
-
// { $setOnInsert: params },
|
|
377
|
-
// { new: true, upsert: true }
|
|
378
|
-
// )
|
|
379
|
-
// .select({ _id: 1 })
|
|
380
|
-
// .exec();
|
|
381
|
-
// if (options.emitImmediately) {
|
|
382
|
-
// taskEventEmitter.emitTaskStatusChanged({
|
|
383
|
-
// id: createdTask.id,
|
|
384
|
-
// name: params.name,
|
|
385
|
-
// status: factory.taskStatus.Ready
|
|
386
|
-
// });
|
|
387
|
-
// }
|
|
388
|
-
// }
|
|
389
359
|
executeById(params) {
|
|
390
360
|
return __awaiter(this, void 0, void 0, function* () {
|
|
361
|
+
const projection = {
|
|
362
|
+
_id: 0,
|
|
363
|
+
id: { $toString: '$_id' },
|
|
364
|
+
// 必要最低限にprojection(2024-04-23~)
|
|
365
|
+
data: 1,
|
|
366
|
+
name: 1,
|
|
367
|
+
status: 1,
|
|
368
|
+
numberOfTried: 1,
|
|
369
|
+
project: 1,
|
|
370
|
+
remainingNumberOfTries: 1,
|
|
371
|
+
runsAt: 1,
|
|
372
|
+
expire: 1
|
|
373
|
+
};
|
|
391
374
|
const doc = yield this.taskModel.findOneAndUpdate({
|
|
392
375
|
status: { $eq: factory.taskStatus.Ready },
|
|
393
376
|
runsAt: { $lt: new Date() },
|
|
@@ -402,30 +385,31 @@ class TaskRepo {
|
|
|
402
385
|
remainingNumberOfTries: -1,
|
|
403
386
|
numberOfTried: 1 // トライ回数増やす
|
|
404
387
|
}
|
|
405
|
-
}, {
|
|
406
|
-
|
|
407
|
-
// 必要最低限にprojection(2024-04-23~)
|
|
408
|
-
projection: {
|
|
409
|
-
data: 1,
|
|
410
|
-
name: 1,
|
|
411
|
-
status: 1,
|
|
412
|
-
numberOfTried: 1,
|
|
413
|
-
project: 1,
|
|
414
|
-
remainingNumberOfTries: 1,
|
|
415
|
-
runsAt: 1,
|
|
416
|
-
expire: 1
|
|
417
|
-
}
|
|
418
|
-
})
|
|
388
|
+
}, { new: true, projection })
|
|
389
|
+
.lean() // lean(2024-09-26~)
|
|
419
390
|
.exec();
|
|
420
391
|
if (doc === null) {
|
|
421
392
|
// tslint:disable-next-line:no-null-keyword
|
|
422
393
|
return null;
|
|
423
394
|
}
|
|
424
|
-
return doc
|
|
395
|
+
return doc;
|
|
425
396
|
});
|
|
426
397
|
}
|
|
427
398
|
executeOneByName(params) {
|
|
428
399
|
return __awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
const projection = {
|
|
401
|
+
_id: 0,
|
|
402
|
+
id: { $toString: '$_id' },
|
|
403
|
+
// 必要最低限にprojection(2024-04-23~)
|
|
404
|
+
data: 1,
|
|
405
|
+
name: 1,
|
|
406
|
+
status: 1,
|
|
407
|
+
numberOfTried: 1,
|
|
408
|
+
project: 1,
|
|
409
|
+
remainingNumberOfTries: 1,
|
|
410
|
+
runsAt: 1,
|
|
411
|
+
expire: 1
|
|
412
|
+
};
|
|
429
413
|
const doc = yield this.taskModel.findOneAndUpdate({
|
|
430
414
|
status: { $eq: factory.taskStatus.Ready },
|
|
431
415
|
runsAt: { $lt: new Date() },
|
|
@@ -440,27 +424,15 @@ class TaskRepo {
|
|
|
440
424
|
remainingNumberOfTries: -1,
|
|
441
425
|
numberOfTried: 1 // トライ回数増やす
|
|
442
426
|
}
|
|
443
|
-
}, {
|
|
444
|
-
new: true,
|
|
445
|
-
// 必要最低限にprojection(2024-04-23~)
|
|
446
|
-
projection: {
|
|
447
|
-
data: 1,
|
|
448
|
-
name: 1,
|
|
449
|
-
status: 1,
|
|
450
|
-
numberOfTried: 1,
|
|
451
|
-
project: 1,
|
|
452
|
-
remainingNumberOfTries: 1,
|
|
453
|
-
runsAt: 1,
|
|
454
|
-
expire: 1
|
|
455
|
-
}
|
|
456
|
-
})
|
|
427
|
+
}, { new: true, projection })
|
|
457
428
|
.sort(sortOrder4executionOfTasks)
|
|
429
|
+
.lean() // lean(2024-09-26~)
|
|
458
430
|
.exec();
|
|
459
431
|
if (doc === null) {
|
|
460
432
|
// tslint:disable-next-line:no-null-keyword
|
|
461
433
|
return null;
|
|
462
434
|
}
|
|
463
|
-
return doc
|
|
435
|
+
return doc;
|
|
464
436
|
});
|
|
465
437
|
}
|
|
466
438
|
/**
|
|
@@ -471,18 +443,25 @@ class TaskRepo {
|
|
|
471
443
|
const runsAtLt = moment(params.now)
|
|
472
444
|
.add(-params.delayInSeconds, 'seconds')
|
|
473
445
|
.toDate();
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
446
|
+
const projection = {
|
|
447
|
+
_id: 0,
|
|
448
|
+
id: { $toString: '$_id' },
|
|
477
449
|
name: 1,
|
|
478
450
|
status: 1
|
|
479
|
-
}
|
|
451
|
+
};
|
|
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
|
+
// })
|
|
480
458
|
.limit(params.limit)
|
|
481
459
|
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
460
|
+
.lean() // lean(2024-09-26~)
|
|
482
461
|
.exec();
|
|
483
462
|
if (delayedTasks.length > 0) {
|
|
484
463
|
delayedTasks.forEach((delayedTask) => {
|
|
485
|
-
|
|
464
|
+
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
486
465
|
id: delayedTask.id,
|
|
487
466
|
name: delayedTask.name,
|
|
488
467
|
status: delayedTask.status
|
|
@@ -540,6 +519,7 @@ class TaskRepo {
|
|
|
540
519
|
const lastTriedAtShoudBeLessThan = moment()
|
|
541
520
|
.add(-params.intervalInMinutes, 'minutes')
|
|
542
521
|
.toDate();
|
|
522
|
+
const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(AVAILABLE_PROJECT_FIELDS.map((key) => ([key, 1]))));
|
|
543
523
|
const doc = yield this.taskModel.findOneAndUpdate({
|
|
544
524
|
status: { $eq: factory.taskStatus.Running },
|
|
545
525
|
lastTriedAt: {
|
|
@@ -552,13 +532,14 @@ class TaskRepo {
|
|
|
552
532
|
status: factory.taskStatus.Aborted,
|
|
553
533
|
dateAborted: new Date()
|
|
554
534
|
}
|
|
555
|
-
}, { new: true })
|
|
535
|
+
}, { new: true, projection })
|
|
536
|
+
.lean() // lean(2024-09-26~)
|
|
556
537
|
.exec();
|
|
557
538
|
if (doc === null) {
|
|
558
539
|
// tslint:disable-next-line:no-null-keyword
|
|
559
540
|
return null;
|
|
560
541
|
}
|
|
561
|
-
return doc
|
|
542
|
+
return doc;
|
|
562
543
|
});
|
|
563
544
|
}
|
|
564
545
|
abortMany(params) {
|
|
@@ -601,23 +582,27 @@ class TaskRepo {
|
|
|
601
582
|
/**
|
|
602
583
|
* 特定タスク検索
|
|
603
584
|
*/
|
|
604
|
-
findById(params
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
585
|
+
// public async findById<T extends factory.taskName>(params: {
|
|
586
|
+
// name: T;
|
|
587
|
+
// id: string;
|
|
588
|
+
// }): Promise<factory.task.ITask<T>> {
|
|
589
|
+
// const doc = await this.taskModel.findOne(
|
|
590
|
+
// {
|
|
591
|
+
// name: { $eq: params.name },
|
|
592
|
+
// _id: { $eq: params.id }
|
|
593
|
+
// },
|
|
594
|
+
// {
|
|
595
|
+
// __v: 0,
|
|
596
|
+
// createdAt: 0,
|
|
597
|
+
// updatedAt: 0
|
|
598
|
+
// }
|
|
599
|
+
// )
|
|
600
|
+
// .exec();
|
|
601
|
+
// if (doc === null) {
|
|
602
|
+
// throw new factory.errors.NotFound('Task');
|
|
603
|
+
// }
|
|
604
|
+
// return doc.toObject();
|
|
605
|
+
// }
|
|
621
606
|
count(params) {
|
|
622
607
|
return __awaiter(this, void 0, void 0, function* () {
|
|
623
608
|
const conditions = TaskRepo.CREATE_MONGO_CONDITIONS(params);
|
|
@@ -629,30 +614,36 @@ class TaskRepo {
|
|
|
629
614
|
/**
|
|
630
615
|
* 検索する
|
|
631
616
|
*/
|
|
632
|
-
|
|
617
|
+
projectFields(params,
|
|
618
|
+
// projection?: IProjection
|
|
619
|
+
inclusion) {
|
|
633
620
|
var _a;
|
|
634
621
|
return __awaiter(this, void 0, void 0, function* () {
|
|
635
622
|
const conditions = TaskRepo.CREATE_MONGO_CONDITIONS(params);
|
|
636
|
-
const positiveProjectionExists = (projection !== undefined && projection !== null)
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
623
|
+
// const positiveProjectionExists: boolean = (projection !== undefined && projection !== null)
|
|
624
|
+
// ? Object.values(projection)
|
|
625
|
+
// .some((value) => value !== 0)
|
|
626
|
+
// : false;
|
|
627
|
+
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
628
|
+
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
629
|
+
positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
// no op
|
|
633
|
+
}
|
|
634
|
+
const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
|
|
635
|
+
const query = this.taskModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
643
636
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
644
637
|
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
645
638
|
query.limit(params.limit)
|
|
646
639
|
.skip(params.limit * (page - 1));
|
|
647
640
|
}
|
|
648
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
649
|
-
/* istanbul ignore else */
|
|
650
641
|
if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.runsAt) !== undefined) {
|
|
651
642
|
query.sort({ runsAt: params.sort.runsAt });
|
|
652
643
|
}
|
|
653
644
|
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
654
|
-
.
|
|
655
|
-
.
|
|
645
|
+
.lean() // lean(2024-09-26~)
|
|
646
|
+
.exec();
|
|
656
647
|
});
|
|
657
648
|
}
|
|
658
649
|
deleteByProject(params) {
|
|
@@ -15,16 +15,13 @@ function findAcceptAction(params) {
|
|
|
15
15
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
var _a, _b;
|
|
17
17
|
// タスク検索
|
|
18
|
-
const task = (yield repos.task.
|
|
18
|
+
const task = (yield repos.task.projectFields({
|
|
19
19
|
limit: 1,
|
|
20
20
|
page: 1,
|
|
21
21
|
id: { $eq: params.sameAs.id },
|
|
22
22
|
project: { id: { $eq: params.project.id } },
|
|
23
23
|
name: factory.taskName.AcceptCOAOffer
|
|
24
|
-
},
|
|
25
|
-
status: 1,
|
|
26
|
-
executionResults: 1
|
|
27
|
-
})).shift();
|
|
24
|
+
}, ['status', 'executionResults'])).shift();
|
|
28
25
|
if (task === undefined) {
|
|
29
26
|
throw new factory.errors.NotFound(factory.taskName.AcceptCOAOffer);
|
|
30
27
|
}
|
|
@@ -60,7 +60,7 @@ function createConfirmPayTransactionTasks(order, simpleOrder) {
|
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
// 冗長なタスク作成を回避
|
|
63
|
-
const existingTasks = yield repos.task.
|
|
63
|
+
const existingTasks = yield repos.task.projectFields({
|
|
64
64
|
limit: 1,
|
|
65
65
|
page: 1,
|
|
66
66
|
project: { id: { $eq: order.project.id } },
|
|
@@ -69,10 +69,12 @@ function createConfirmPayTransactionTasks(order, simpleOrder) {
|
|
|
69
69
|
object: { transactionNumber: { $eq: invoice.paymentMethodId } },
|
|
70
70
|
purpose: { orderNumber: { $eq: order.orderNumber } }
|
|
71
71
|
}
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
}, ['id']
|
|
73
|
+
// {
|
|
74
|
+
// data: 0, executionResults: 0, name: 0, numberOfTried: 0,
|
|
75
|
+
// remainingNumberOfTries: 0, runsAt: 0, status: 0
|
|
76
|
+
// }
|
|
77
|
+
);
|
|
76
78
|
if (existingTasks.length === 0) {
|
|
77
79
|
const data = {
|
|
78
80
|
project: order.project,
|
|
@@ -475,16 +475,13 @@ function findAuthorizeAction(params) {
|
|
|
475
475
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
476
476
|
var _a, _b;
|
|
477
477
|
// タスク検索
|
|
478
|
-
const task = (yield repos.task.
|
|
478
|
+
const task = (yield repos.task.projectFields({
|
|
479
479
|
limit: 1,
|
|
480
480
|
page: 1,
|
|
481
481
|
id: { $eq: params.sameAs.id },
|
|
482
482
|
project: { id: { $eq: params.project.id } },
|
|
483
483
|
name: factory.taskName.AuthorizePayment
|
|
484
|
-
},
|
|
485
|
-
status: 1,
|
|
486
|
-
executionResults: 1
|
|
487
|
-
})).shift();
|
|
484
|
+
}, ['status', 'executionResults'])).shift();
|
|
488
485
|
if (task === undefined) {
|
|
489
486
|
throw new factory.errors.NotFound(factory.taskName.AuthorizePayment);
|
|
490
487
|
}
|
|
@@ -529,16 +526,13 @@ function findCheckAction(params) {
|
|
|
529
526
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
530
527
|
var _a, _b;
|
|
531
528
|
// タスク検索
|
|
532
|
-
const task = (yield repos.task.
|
|
529
|
+
const task = (yield repos.task.projectFields({
|
|
533
530
|
limit: 1,
|
|
534
531
|
page: 1,
|
|
535
532
|
id: { $eq: params.sameAs.id },
|
|
536
533
|
project: { id: { $eq: params.project.id } },
|
|
537
534
|
name: factory.taskName.CheckMovieTicket
|
|
538
|
-
},
|
|
539
|
-
status: 1,
|
|
540
|
-
executionResults: 1
|
|
541
|
-
})).shift();
|
|
535
|
+
}, ['status', 'executionResults'])).shift();
|
|
542
536
|
if (task === undefined) {
|
|
543
537
|
throw new factory.errors.NotFound(factory.taskName.CheckMovieTicket);
|
|
544
538
|
}
|
|
@@ -588,16 +582,13 @@ function findAcceptAction(params) {
|
|
|
588
582
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
589
583
|
var _a, _b;
|
|
590
584
|
// タスク検索
|
|
591
|
-
const task = (yield repos.task.
|
|
585
|
+
const task = (yield repos.task.projectFields({
|
|
592
586
|
limit: 1,
|
|
593
587
|
page: 1,
|
|
594
588
|
id: { $eq: params.sameAs.id },
|
|
595
589
|
project: { id: { $eq: params.project.id } },
|
|
596
590
|
name: factory.taskName.PublishPaymentUrl
|
|
597
|
-
},
|
|
598
|
-
status: 1,
|
|
599
|
-
executionResults: 1
|
|
600
|
-
})).shift();
|
|
591
|
+
}, ['status', 'executionResults'])).shift();
|
|
601
592
|
if (task === undefined) {
|
|
602
593
|
throw new factory.errors.NotFound(factory.taskName.PublishPaymentUrl);
|
|
603
594
|
}
|
|
@@ -171,9 +171,9 @@ exports.abort = abort;
|
|
|
171
171
|
function notifyAbortedTasks(params) {
|
|
172
172
|
return (repos, settings, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
173
173
|
const { abortedTasksWithoutReport } = settings;
|
|
174
|
-
const abortedTasks = yield repos.task.
|
|
174
|
+
const abortedTasks = yield repos.task.projectFields(Object.assign({ statuses: [factory.taskStatus.Aborted], dateAborted: { $gte: params.dateAbortedGte } }, (abortedTasksWithoutReport.length > 0)
|
|
175
175
|
? { name: { $nin: abortedTasksWithoutReport } }
|
|
176
|
-
: undefined));
|
|
176
|
+
: undefined), []);
|
|
177
177
|
if (abortedTasks.length > 0) {
|
|
178
178
|
if (notification === undefined) {
|
|
179
179
|
notification = yield Promise.resolve().then(() => require('./notification'));
|
package/package.json
CHANGED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-implicit-dependencies no-console
|
|
2
|
-
import { chevre } from '../../../lib/index';
|
|
3
|
-
|
|
4
|
-
import * as mongoose from 'mongoose';
|
|
5
|
-
|
|
6
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
-
|
|
8
|
-
mongoose.Model.on('index', (...args) => {
|
|
9
|
-
console.error('******** index event emitted. ********\n', args);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
async function main() {
|
|
13
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
14
|
-
|
|
15
|
-
const indexes = await mongoose.connection.db.collection('tasks')
|
|
16
|
-
.indexes();
|
|
17
|
-
// console.log(indexes);
|
|
18
|
-
console.log(indexes.length, 'indexes found');
|
|
19
|
-
|
|
20
|
-
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
21
|
-
const tasks = await taskRepo.search(
|
|
22
|
-
{
|
|
23
|
-
limit: 1,
|
|
24
|
-
page: 1
|
|
25
|
-
// typeOf: { $eq: chevre.factory.actionType.CheckAction },
|
|
26
|
-
// project: { id: { $eq: project.id } },
|
|
27
|
-
// object: {
|
|
28
|
-
// movieTickets: {
|
|
29
|
-
// identifier: { $eq: '0947524082' },
|
|
30
|
-
// serviceOutput: { reservationFor: { id: { $eq: 'clhvvbpyn' } } }
|
|
31
|
-
// }
|
|
32
|
-
// }
|
|
33
|
-
// instrument: { transactionNumber: { $eq: 'x' } },
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
console.log('tasks:', tasks);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
main()
|
|
40
|
-
.then(() => {
|
|
41
|
-
console.log('success!');
|
|
42
|
-
})
|
|
43
|
-
.catch(console.error);
|