@chevre/domain 22.9.0-alpha.54 → 22.9.0-alpha.56
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/{aggregateAllEvents2.ts → executeTaskIfExists.ts} +19 -10
- package/example/src/chevre/transaction/startExportTasks.ts +4 -3
- package/lib/chevre/repo/mongoose/schemas/task.js +6 -9
- package/lib/chevre/repo/task.d.ts +12 -3
- package/lib/chevre/repo/task.js +15 -6
- package/lib/chevre/repo/transaction.d.ts +7 -5
- package/lib/chevre/repo/transaction.js +30 -13
- package/lib/chevre/service/task.d.ts +10 -4
- package/lib/chevre/service/task.js +8 -9
- package/lib/chevre/service/transaction.d.ts +6 -7
- package/lib/chevre/service/transaction.js +6 -10
- package/package.json +1 -1
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
|
-
/**
|
|
3
|
-
* イベント集計タスク実行
|
|
4
|
-
*/
|
|
5
2
|
import { chevre } from '../../../lib/index';
|
|
6
3
|
|
|
7
4
|
import * as mongoose from 'mongoose';
|
|
8
5
|
import * as redis from 'redis';
|
|
9
6
|
|
|
10
|
-
export async function
|
|
7
|
+
export async function executeTaskIfExists() {
|
|
11
8
|
const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
12
9
|
socket: {
|
|
13
10
|
port: Number(<string>process.env.REDIS_PORT),
|
|
@@ -21,8 +18,8 @@ export async function aggregateScreeningEvent() {
|
|
|
21
18
|
|
|
22
19
|
let count = 0;
|
|
23
20
|
|
|
24
|
-
const MAX_NUBMER_OF_PARALLEL_TASKS =
|
|
25
|
-
const INTERVAL_MILLISECONDS =
|
|
21
|
+
const MAX_NUBMER_OF_PARALLEL_TASKS = 1;
|
|
22
|
+
const INTERVAL_MILLISECONDS = 1000;
|
|
26
23
|
|
|
27
24
|
setInterval(
|
|
28
25
|
async () => {
|
|
@@ -34,9 +31,21 @@ export async function aggregateScreeningEvent() {
|
|
|
34
31
|
|
|
35
32
|
try {
|
|
36
33
|
console.log('executing...', count);
|
|
37
|
-
await (await chevre.service.task.createService()).
|
|
38
|
-
name: chevre.factory.taskName.AggregateScreeningEvent,
|
|
39
|
-
executor: { name: 'sample' }
|
|
34
|
+
await (await chevre.service.task.createService()).executeOneIfExists({
|
|
35
|
+
// name: chevre.factory.taskName.AggregateScreeningEvent,
|
|
36
|
+
executor: { name: 'sample' },
|
|
37
|
+
runsAt: { $lt: new Date() },
|
|
38
|
+
name: {
|
|
39
|
+
$nin: [
|
|
40
|
+
chevre.factory.taskName.DeleteTransaction,
|
|
41
|
+
chevre.factory.taskName.ImportEventCapacitiesFromCOA,
|
|
42
|
+
chevre.factory.taskName.ImportEventsFromCOA,
|
|
43
|
+
chevre.factory.taskName.AcceptCOAOffer,
|
|
44
|
+
chevre.factory.taskName.CheckMovieTicket,
|
|
45
|
+
chevre.factory.taskName.AuthorizePayment,
|
|
46
|
+
chevre.factory.taskName.PublishPaymentUrl
|
|
47
|
+
]
|
|
48
|
+
}
|
|
40
49
|
})({
|
|
41
50
|
connection: mongoose.connection,
|
|
42
51
|
redisClient,
|
|
@@ -64,7 +73,7 @@ export async function aggregateScreeningEvent() {
|
|
|
64
73
|
);
|
|
65
74
|
}
|
|
66
75
|
|
|
67
|
-
|
|
76
|
+
executeTaskIfExists()
|
|
68
77
|
.then(() => {
|
|
69
78
|
console.log('success!');
|
|
70
79
|
})
|
|
@@ -8,9 +8,10 @@ async function main() {
|
|
|
8
8
|
|
|
9
9
|
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
10
10
|
const result = await transactionRepo.startExportTasks({
|
|
11
|
-
typeOf: { $in: [chevre.factory.transactionType.PlaceOrder] },
|
|
12
|
-
status: chevre.factory.transactionStatusType.Confirmed,
|
|
13
|
-
tasksExportAction: { agent: { name: 'xxx' } }
|
|
11
|
+
// typeOf: { $in: [chevre.factory.transactionType.PlaceOrder] },
|
|
12
|
+
status: { $eq: chevre.factory.transactionStatusType.Confirmed },
|
|
13
|
+
tasksExportAction: { agent: { name: 'xxx' } },
|
|
14
|
+
endDate: { $lt: new Date() }
|
|
14
15
|
});
|
|
15
16
|
console.log(result);
|
|
16
17
|
}
|
|
@@ -9,16 +9,13 @@ const modelName = 'Task';
|
|
|
9
9
|
exports.modelName = modelName;
|
|
10
10
|
const schemaDefinition = {
|
|
11
11
|
identifier: String,
|
|
12
|
-
project: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
runsAt: Date,
|
|
19
|
-
remainingNumberOfTries: Number,
|
|
12
|
+
project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
13
|
+
name: { type: String, required: true },
|
|
14
|
+
status: { type: String, required: true },
|
|
15
|
+
runsAt: { type: Date, required: true },
|
|
16
|
+
remainingNumberOfTries: { type: Number, required: true },
|
|
17
|
+
numberOfTried: { type: Number, required: true },
|
|
20
18
|
lastTriedAt: Date,
|
|
21
|
-
numberOfTried: Number,
|
|
22
19
|
executionResults: [mongoose_1.SchemaTypes.Mixed],
|
|
23
20
|
executor: mongoose_1.SchemaTypes.Mixed,
|
|
24
21
|
data: mongoose_1.SchemaTypes.Mixed,
|
|
@@ -71,12 +71,21 @@ export declare class TaskRepo {
|
|
|
71
71
|
name: string;
|
|
72
72
|
};
|
|
73
73
|
}): Promise<IExecutableTask<factory.taskName> | null>;
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
/**
|
|
75
|
+
* support no name(2025-03-04~)
|
|
76
|
+
*/
|
|
77
|
+
executeOne(params: {
|
|
78
|
+
name?: {
|
|
79
|
+
$eq?: factory.taskName;
|
|
80
|
+
$nin?: factory.taskName[];
|
|
81
|
+
};
|
|
76
82
|
executor: {
|
|
77
83
|
name: string;
|
|
78
84
|
};
|
|
79
|
-
|
|
85
|
+
runsAt: {
|
|
86
|
+
$lt: Date;
|
|
87
|
+
};
|
|
88
|
+
}): Promise<IExecutableTask<factory.taskName> | null>;
|
|
80
89
|
/**
|
|
81
90
|
* emit OnTaskStatusChanged on delayed tasks
|
|
82
91
|
*/
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -395,8 +395,15 @@ class TaskRepo {
|
|
|
395
395
|
return doc;
|
|
396
396
|
});
|
|
397
397
|
}
|
|
398
|
-
|
|
398
|
+
/**
|
|
399
|
+
* support no name(2025-03-04~)
|
|
400
|
+
*/
|
|
401
|
+
executeOne(params) {
|
|
399
402
|
return __awaiter(this, void 0, void 0, function* () {
|
|
403
|
+
var _a, _b;
|
|
404
|
+
if (!(params.runsAt.$lt instanceof Date)) {
|
|
405
|
+
throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
406
|
+
}
|
|
400
407
|
const projection = {
|
|
401
408
|
_id: 0,
|
|
402
409
|
id: { $toString: '$_id' },
|
|
@@ -410,11 +417,13 @@ class TaskRepo {
|
|
|
410
417
|
runsAt: 1,
|
|
411
418
|
expires: 1
|
|
412
419
|
};
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
420
|
+
const nameEq = (_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq;
|
|
421
|
+
const nameNin = (_b = params.name) === null || _b === void 0 ? void 0 : _b.$nin;
|
|
422
|
+
const doc = yield this.taskModel.findOneAndUpdate(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: params.runsAt.$lt } }, (typeof nameEq === 'string' || Array.isArray(nameNin))
|
|
423
|
+
? {
|
|
424
|
+
name: Object.assign(Object.assign({}, (typeof nameEq === 'string') ? { $eq: nameEq } : undefined), (Array.isArray(nameNin)) ? { $nin: nameNin } : undefined)
|
|
425
|
+
}
|
|
426
|
+
: undefined), {
|
|
418
427
|
$set: {
|
|
419
428
|
status: factory.taskStatus.Running, // 実行中に変更
|
|
420
429
|
lastTriedAt: new Date(),
|
|
@@ -110,18 +110,20 @@ export declare class TransactionRepo {
|
|
|
110
110
|
/**
|
|
111
111
|
* タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
|
|
112
112
|
*/
|
|
113
|
-
startExportTasks
|
|
114
|
-
|
|
115
|
-
$
|
|
113
|
+
startExportTasks(params: {
|
|
114
|
+
status?: {
|
|
115
|
+
$eq?: factory.transactionStatusType;
|
|
116
116
|
};
|
|
117
|
-
status: factory.transactionStatusType;
|
|
118
117
|
id?: string;
|
|
119
118
|
tasksExportAction: {
|
|
120
119
|
agent: {
|
|
121
120
|
name: string;
|
|
122
121
|
};
|
|
123
122
|
};
|
|
124
|
-
|
|
123
|
+
endDate: {
|
|
124
|
+
$lt: Date;
|
|
125
|
+
};
|
|
126
|
+
}): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'> | null>;
|
|
125
127
|
reexportTasksByExportAction(params: {
|
|
126
128
|
intervalInMinutes: number;
|
|
127
129
|
}): Promise<void>;
|
|
@@ -553,25 +553,41 @@ class TransactionRepo {
|
|
|
553
553
|
*/
|
|
554
554
|
startExportTasks(params) {
|
|
555
555
|
return __awaiter(this, void 0, void 0, function* () {
|
|
556
|
-
var _a;
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
556
|
+
var _a, _b;
|
|
557
|
+
const statusEq = (_a = params.status) === null || _a === void 0 ? void 0 : _a.$eq;
|
|
558
|
+
const endDateLt = (_b = params.endDate) === null || _b === void 0 ? void 0 : _b.$lt;
|
|
559
|
+
if (typeof statusEq === 'string') {
|
|
560
|
+
switch (statusEq) {
|
|
561
|
+
case factory.transactionStatusType.InProgress:
|
|
562
|
+
throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
|
|
563
|
+
default:
|
|
564
|
+
// no op
|
|
565
|
+
}
|
|
562
566
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
567
|
+
if (!(endDateLt instanceof Date)) {
|
|
568
|
+
throw new factory.errors.Argument('endDate.$lt', 'must be Date');
|
|
569
|
+
}
|
|
570
|
+
// const typeOfIn = params.typeOf?.$in;
|
|
571
|
+
const sort = {
|
|
572
|
+
startDate: factory.sortType.Ascending
|
|
573
|
+
};
|
|
574
|
+
return this.transactionModel.findOneAndUpdate(Object.assign({
|
|
575
|
+
// ...(Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined,
|
|
576
|
+
status: Object.assign({}, (typeof statusEq === 'string')
|
|
577
|
+
? { $eq: statusEq }
|
|
578
|
+
: {
|
|
579
|
+
$in: [
|
|
580
|
+
factory.transactionStatusType.Canceled,
|
|
581
|
+
factory.transactionStatusType.Confirmed,
|
|
582
|
+
factory.transactionStatusType.Expired
|
|
583
|
+
]
|
|
584
|
+
}), 'tasksExportAction.actionStatus': {
|
|
568
585
|
$exists: true,
|
|
569
586
|
$eq: factory.actionStatusType.PotentialActionStatus
|
|
570
|
-
} }
|
|
587
|
+
}, endDate: { $exists: true, $lt: endDateLt } }, (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), {
|
|
571
588
|
'tasksExportAction.actionStatus': factory.actionStatusType.ActiveActionStatus,
|
|
572
589
|
'tasksExportAction.agent': { name: params.tasksExportAction.agent.name },
|
|
573
590
|
'tasksExportAction.startDate': new Date()
|
|
574
|
-
// tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting // discontinue(2024-06-20~)
|
|
575
591
|
}, {
|
|
576
592
|
new: true,
|
|
577
593
|
projection: {
|
|
@@ -581,6 +597,7 @@ class TransactionRepo {
|
|
|
581
597
|
typeOf: 1
|
|
582
598
|
}
|
|
583
599
|
})
|
|
600
|
+
.sort(sort)
|
|
584
601
|
.lean() // 2024-08-26~
|
|
585
602
|
.exec()
|
|
586
603
|
// tslint:disable-next-line:no-null-keyword
|
|
@@ -47,16 +47,22 @@ declare function executeById(params: {
|
|
|
47
47
|
};
|
|
48
48
|
}): IOperation<void>;
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* support no name(2025-03-04~)
|
|
51
51
|
*/
|
|
52
|
-
declare function
|
|
53
|
-
name
|
|
52
|
+
declare function executeOneIfExists(params: {
|
|
53
|
+
name?: {
|
|
54
|
+
$eq?: factory.taskName;
|
|
55
|
+
$nin?: factory.taskName[];
|
|
56
|
+
};
|
|
54
57
|
executor: {
|
|
55
58
|
/**
|
|
56
59
|
* タスク実行者名称
|
|
57
60
|
*/
|
|
58
61
|
name: string;
|
|
59
62
|
};
|
|
63
|
+
runsAt: {
|
|
64
|
+
$lt: Date;
|
|
65
|
+
};
|
|
60
66
|
}): IOperation<void>;
|
|
61
67
|
/**
|
|
62
68
|
* タスクを実行する
|
|
@@ -75,4 +81,4 @@ declare function abort(params: {
|
|
|
75
81
|
declare function notifyAbortedTasks(params: {
|
|
76
82
|
dateAbortedGte: Date;
|
|
77
83
|
}): TaskOperation<void>;
|
|
78
|
-
export { ICallResult, IExecutableTaskKeys, IOperationExecute, executeById,
|
|
84
|
+
export { ICallResult, IExecutableTaskKeys, IOperationExecute, executeById, executeOneIfExists, execute, abort, notifyAbortedTasks };
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.executeById = executeById;
|
|
13
|
-
exports.
|
|
13
|
+
exports.executeOneIfExists = executeOneIfExists;
|
|
14
14
|
exports.execute = execute;
|
|
15
15
|
exports.abort = abort;
|
|
16
16
|
exports.notifyAbortedTasks = notifyAbortedTasks;
|
|
@@ -49,30 +49,29 @@ function executeById(params) {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* support no name(2025-03-04~)
|
|
53
53
|
*/
|
|
54
|
-
function
|
|
54
|
+
function executeOneIfExists(params) {
|
|
55
55
|
return (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
var _a;
|
|
56
57
|
const taskRepo = new (yield Promise.resolve().then(() => require('../repo/task'))).TaskRepo(settings.connection);
|
|
57
58
|
// 未実行のタスクを取得
|
|
58
59
|
// tslint:disable-next-line:no-null-keyword
|
|
59
60
|
let task = null;
|
|
60
61
|
try {
|
|
61
|
-
task = yield taskRepo.
|
|
62
|
-
|
|
63
|
-
executor: { name: params.executor.name }
|
|
64
|
-
});
|
|
62
|
+
task = yield taskRepo.executeOne(Object.assign({ executor: { name: params.executor.name }, runsAt: { $lt: params.runsAt.$lt } }, (params.name !== undefined) ? { name: params.name } : undefined));
|
|
63
|
+
debug('executable task found.', task, params.runsAt.$lt);
|
|
65
64
|
}
|
|
66
65
|
catch (error) {
|
|
67
66
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
68
67
|
/* istanbul ignore next */
|
|
69
|
-
debug('
|
|
68
|
+
debug('executeOne error:', error);
|
|
70
69
|
}
|
|
71
70
|
// タスクがなければ終了
|
|
72
71
|
if (task !== null) {
|
|
73
72
|
yield execute(task)(settings, {
|
|
74
73
|
executeById: false,
|
|
75
|
-
executeByName:
|
|
74
|
+
executeByName: (typeof ((_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq) === 'string')
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
});
|
|
@@ -39,17 +39,13 @@ export type IExportTasksOperation<T> = (repos: {
|
|
|
39
39
|
task: TaskRepo;
|
|
40
40
|
transaction: TransactionRepo;
|
|
41
41
|
}) => Promise<T>;
|
|
42
|
-
|
|
43
|
-
* ひとつの取引のタスクをエクスポートする
|
|
44
|
-
*/
|
|
45
|
-
export declare function exportTasks<T extends factory.transactionType>(params: {
|
|
42
|
+
export declare function exportOneTransactionTasksIfExists(params: {
|
|
46
43
|
/**
|
|
47
44
|
* タスク実行日時バッファ
|
|
48
45
|
*/
|
|
49
46
|
runsTasksAfterInSeconds?: number;
|
|
50
|
-
status
|
|
51
|
-
|
|
52
|
-
$in: T[];
|
|
47
|
+
status?: {
|
|
48
|
+
$eq?: factory.transactionStatusType;
|
|
53
49
|
};
|
|
54
50
|
id?: string;
|
|
55
51
|
tasksExportAction: {
|
|
@@ -57,4 +53,7 @@ export declare function exportTasks<T extends factory.transactionType>(params: {
|
|
|
57
53
|
name: string;
|
|
58
54
|
};
|
|
59
55
|
};
|
|
56
|
+
endDate: {
|
|
57
|
+
$lt: Date;
|
|
58
|
+
};
|
|
60
59
|
}): IExportTasksOperation<void>;
|
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.deleteTransaction = exports.returnOrder = exports.placeOrder = exports.moneyTransfer = void 0;
|
|
13
13
|
exports.updateAgent = updateAgent;
|
|
14
|
-
exports.
|
|
14
|
+
exports.exportOneTransactionTasksIfExists = exportOneTransactionTasksIfExists;
|
|
15
15
|
/**
|
|
16
16
|
* 取引サービス
|
|
17
17
|
*/
|
|
@@ -109,16 +109,12 @@ function updateAgent(params) {
|
|
|
109
109
|
// return newAgent;
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return (repos
|
|
117
|
-
// settings: Settings
|
|
118
|
-
) => __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
const transaction = yield repos.transaction.startExportTasks(Object.assign(Object.assign({ status: params.status, tasksExportAction: {
|
|
112
|
+
function exportOneTransactionTasksIfExists(params) {
|
|
113
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
var _a;
|
|
115
|
+
const transaction = yield repos.transaction.startExportTasks(Object.assign(Object.assign({ tasksExportAction: {
|
|
120
116
|
agent: { name: params.tasksExportAction.agent.name }
|
|
121
|
-
} }, (params.
|
|
117
|
+
}, endDate: { $lt: params.endDate.$lt } }, (typeof params.id === 'string') ? { id: params.id } : undefined), (typeof ((_a = params.status) === null || _a === void 0 ? void 0 : _a.$eq) === 'string') ? { status: params.status } : undefined));
|
|
122
118
|
if (transaction === null) {
|
|
123
119
|
return;
|
|
124
120
|
}
|
package/package.json
CHANGED