@chevre/domain 26.0.0-alpha.2 → 26.0.0-alpha.20
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/lib/chevre/eventEmitter/task.d.ts +8 -23
- package/lib/chevre/eventEmitter/task.js +2 -2
- package/lib/chevre/repo/adminAsyncAction.d.ts +2 -2
- package/lib/chevre/repo/adminScheduledTask.d.ts +1 -1
- package/lib/chevre/repo/adminTask.d.ts +25 -5
- package/lib/chevre/repo/adminTask.js +41 -6
- package/lib/chevre/repo/aggregateScheduledTask.d.ts +32 -0
- package/lib/chevre/repo/aggregateScheduledTask.js +136 -0
- package/lib/chevre/repo/asyncAction.d.ts +2 -2
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +1 -0
- package/lib/chevre/repo/mongoose/schemas/task.d.ts +2 -5
- package/lib/chevre/repo/mongoose/schemas/task.js +21 -32
- package/lib/chevre/repo/orderInTransaction.d.ts +0 -3
- package/lib/chevre/repo/orderInTransaction.js +30 -22
- package/lib/chevre/repo/scheduledTask.d.ts +5 -2
- package/lib/chevre/repo/scheduledTask.js +3 -25
- package/lib/chevre/repo/task.d.ts +25 -172
- package/lib/chevre/repo/task.js +19 -475
- package/lib/chevre/repo/taskDelayed.d.ts +87 -0
- package/lib/chevre/repo/taskDelayed.js +224 -0
- package/lib/chevre/repo/taskRunning.d.ts +35 -0
- package/lib/chevre/repo/taskRunning.js +89 -0
- package/lib/chevre/repository.d.ts +10 -0
- package/lib/chevre/repository.js +24 -2
- package/lib/chevre/service/aggregation/system.d.ts +10 -2
- package/lib/chevre/service/aggregation/system.js +42 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +5 -25
- package/lib/chevre/service/asyncAction.d.ts +2 -2
- package/lib/chevre/service/asyncAction.js +1 -4
- package/lib/chevre/service/asyncActionHandler/onOperationFailed.d.ts +2 -2
- package/lib/chevre/service/asyncActionHandler/onOperationFailed.js +0 -2
- package/lib/chevre/service/asyncActionHandler.d.ts +4 -4
- package/lib/chevre/service/asyncActionHandler.js +11 -13
- package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +0 -4
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +19 -19
- package/lib/chevre/service/order/confirmPayTransaction.js +4 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +4 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
- package/lib/chevre/service/payment/any/findAcceptAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findAcceptAction.js +19 -19
- package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findAuthorizeAction.js +19 -19
- package/lib/chevre/service/payment/any/findCheckAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findCheckAction.js +19 -19
- package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +0 -2
- package/lib/chevre/service/payment/any/publishPaymentUrl.js +2 -2
- package/lib/chevre/service/project.d.ts +0 -3
- package/lib/chevre/service/project.js +0 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -2
- package/lib/chevre/service/scheduledTask.d.ts +1 -4
- package/lib/chevre/service/scheduledTask.js +3 -10
- package/lib/chevre/service/scheduledTaskHandler/onOperationFailed.js +1 -2
- package/lib/chevre/service/scheduledTaskHandler.js +0 -13
- package/lib/chevre/service/task/acceptCOAOffer.js +1 -14
- package/lib/chevre/service/task/authorizePayment.js +1 -7
- package/lib/chevre/service/task/checkMovieTicket.js +1 -7
- package/lib/chevre/service/task/confirmReserveTransaction.js +3 -1
- package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +4 -1
- package/lib/chevre/service/task/importEventsFromCOA.js +4 -1
- package/lib/chevre/service/task/importOffersFromCOA.js +5 -5
- package/lib/chevre/service/task/publishPaymentUrl.js +2 -13
- package/lib/chevre/service/task/syncResourcesFromCOA.js +1 -5
- package/lib/chevre/service/task/voidReserveTransaction.js +5 -8
- package/lib/chevre/service/task.d.ts +3 -22
- package/lib/chevre/service/task.js +8 -40
- package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +3 -2
- package/lib/chevre/service/taskHandler/onOperationFailed.js +5 -16
- package/lib/chevre/service/taskHandler.d.ts +1 -2
- package/lib/chevre/service/taskHandler.js +7 -53
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +8 -4
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +55 -103
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -0
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +14 -10
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +13 -3
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +48 -51
- package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
- package/lib/chevre/service/transaction/returnOrder.js +15 -13
- package/lib/chevre/service/transaction.d.ts +2 -0
- package/lib/chevre/service/transaction.js +0 -2
- package/lib/chevre/taskSettings.d.ts +4 -4
- package/package.json +2 -2
|
@@ -16,9 +16,6 @@ interface IReadyTask {
|
|
|
16
16
|
id: string;
|
|
17
17
|
name?: factory.taskName;
|
|
18
18
|
status: factory.taskStatus.Ready;
|
|
19
|
-
remainingNumberOfTries?: never;
|
|
20
|
-
expires?: Date;
|
|
21
|
-
executionResult?: never;
|
|
22
19
|
}
|
|
23
20
|
/**
|
|
24
21
|
* タスク名不明の遅延実行中タスク
|
|
@@ -27,9 +24,6 @@ interface IRunningTask {
|
|
|
27
24
|
id: string;
|
|
28
25
|
status: factory.taskStatus.Running;
|
|
29
26
|
name?: never;
|
|
30
|
-
remainingNumberOfTries?: never;
|
|
31
|
-
expires?: never;
|
|
32
|
-
executionResult?: never;
|
|
33
27
|
}
|
|
34
28
|
/**
|
|
35
29
|
* タスク名指定での遅延実行中タスク
|
|
@@ -38,35 +32,26 @@ interface IRunningTaskByName {
|
|
|
38
32
|
id: string;
|
|
39
33
|
status: factory.taskStatus.Running;
|
|
40
34
|
name: factory.taskName;
|
|
41
|
-
remainingNumberOfTries?: never;
|
|
42
|
-
expires?: never;
|
|
43
|
-
executionResult?: never;
|
|
44
35
|
}
|
|
45
36
|
/**
|
|
46
|
-
*
|
|
37
|
+
* タスクステータス変更イベント発火時パラメータとしてのタスク
|
|
47
38
|
*/
|
|
48
|
-
|
|
39
|
+
type IChangedTask = IReadyTask | IRunningTask | IRunningTaskByName;
|
|
40
|
+
type IOperationExecute<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
41
|
+
interface ITaskAsNextFunctionParam {
|
|
49
42
|
id: string;
|
|
50
43
|
status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
|
|
51
44
|
name: factory.taskName;
|
|
52
|
-
executionResult: factory.task.IExecutionResult;
|
|
53
|
-
/**
|
|
54
|
-
* 実行されたタスクの残り試行回数
|
|
55
|
-
*/
|
|
56
|
-
remainingNumberOfTries: number;
|
|
57
|
-
expires?: never;
|
|
58
45
|
}
|
|
59
|
-
type
|
|
60
|
-
type
|
|
61
|
-
type INextFunction = (task: IExecutedTask) => IOperationExecute<void>;
|
|
62
|
-
type IOnTaskStatusChangedListener = (task: IChangedTask, next?: INextFunction) => void;
|
|
46
|
+
type IAsyncActionNextFunction = (task: ITaskAsNextFunctionParam) => IOperationExecute<void>;
|
|
47
|
+
type IOnTaskStatusChangedListener = (task: IChangedTask) => void;
|
|
63
48
|
type RedisClientType = ReturnType<typeof createClient>;
|
|
64
49
|
/**
|
|
65
50
|
* タスクイベントエミッター
|
|
66
51
|
*/
|
|
67
52
|
declare class TaskEventEmitter extends EventEmitter {
|
|
68
53
|
onTaskStatusChanged(listener: IOnTaskStatusChangedListener): void;
|
|
69
|
-
emitTaskStatusChanged(task: IChangedTask
|
|
54
|
+
emitTaskStatusChanged(task: IChangedTask): void;
|
|
70
55
|
}
|
|
71
56
|
declare const taskEventEmitter: TaskEventEmitter;
|
|
72
|
-
export { IChangedTask, IReadyTask, IRunningTask, IRunningTaskByName,
|
|
57
|
+
export { IChangedTask, IReadyTask, IRunningTask, IRunningTaskByName, IExecuteSettings, IOnTaskStatusChangedListener, taskEventEmitter, ITaskAsNextFunctionParam, IAsyncActionNextFunction };
|
|
@@ -14,8 +14,8 @@ class TaskEventEmitter extends events_1.EventEmitter {
|
|
|
14
14
|
this.on(EventName.OnTaskStatusChanged, listener);
|
|
15
15
|
}
|
|
16
16
|
// support next function required(2025-05-25~)
|
|
17
|
-
emitTaskStatusChanged(task
|
|
18
|
-
this.emit(EventName.OnTaskStatusChanged, task
|
|
17
|
+
emitTaskStatusChanged(task) {
|
|
18
|
+
this.emit(EventName.OnTaskStatusChanged, task);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
const taskEventEmitter = new TaskEventEmitter();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
2
|
import { factory } from '../factory';
|
|
3
|
-
import {
|
|
3
|
+
import { IDocType } from './mongoose/schemas/asyncAction';
|
|
4
4
|
import type { IExecutableTask } from '../taskSettings';
|
|
5
5
|
export type IExecutableAsyncAction = Pick<IExecutableTask<factory.taskName>, 'data' | 'expires' | 'id' | 'name' | 'project' | 'runsAt' | 'status'>;
|
|
6
6
|
type IKeyOfProjection = keyof factory.task.ITask<factory.taskName> | 'expires';
|
|
@@ -9,7 +9,7 @@ type IFindParams = Pick<factory.task.ISearchConditions, 'id' | 'name' | 'project
|
|
|
9
9
|
* 非同期アクション管理リポジトリ
|
|
10
10
|
*/
|
|
11
11
|
export declare class AdminAsyncActionRepo {
|
|
12
|
-
readonly asyncActionModel
|
|
12
|
+
private readonly asyncActionModel;
|
|
13
13
|
constructor(connection: Connection);
|
|
14
14
|
static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status'>): FilterQuery<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask>[];
|
|
15
15
|
findAsyncActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
2
|
import { factory } from '../factory';
|
|
3
3
|
import { IDocType } from './mongoose/schemas/scheduledTasks';
|
|
4
|
-
type IKeyOfProjection = keyof
|
|
4
|
+
type IKeyOfProjection = keyof IDocType;
|
|
5
5
|
type IFindParams = Pick<factory.task.ISearchConditions, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status' | 'limit' | 'page' | 'sort'>;
|
|
6
6
|
/**
|
|
7
7
|
* 予定タスク管理リポジトリ
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AnyKeys, Connection, FilterQuery, ProjectionType } from 'mongoose';
|
|
2
2
|
import { factory } from '../factory';
|
|
3
3
|
import { IDocType } from './mongoose/schemas/task';
|
|
4
|
-
type IKeyOfProjection = keyof factory.task.ITask<factory.taskName
|
|
4
|
+
type IKeyOfProjection = keyof factory.task.ITask<factory.taskName>;
|
|
5
5
|
/**
|
|
6
6
|
* タスク管理リポジトリ
|
|
7
7
|
*/
|
|
@@ -16,14 +16,34 @@ export declare class AdminTaskRepo {
|
|
|
16
16
|
* 検索する
|
|
17
17
|
*/
|
|
18
18
|
findTasks(params: factory.task.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.task.ITask<factory.taskName>[]>;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* cron:notifyLatency専用
|
|
21
|
+
*/
|
|
22
|
+
countDelayedTasks(params: {
|
|
23
|
+
delayInSeconds: number;
|
|
24
|
+
name: {
|
|
25
|
+
$nin?: factory.taskName[];
|
|
26
|
+
};
|
|
27
|
+
limit?: number;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
count: number;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* 不要なタスクを削除する
|
|
33
|
+
*/
|
|
34
|
+
deleteRunsAtPassedCertainPeriod(params: {
|
|
35
|
+
runsAt: {
|
|
36
|
+
$lt: Date;
|
|
37
|
+
};
|
|
38
|
+
}): Promise<import("mongodb").DeleteResult>;
|
|
39
|
+
getCursor(conditions: FilterQuery<factory.task.ITask<factory.taskName>>, projection: ProjectionType<factory.task.ITask<factory.taskName>>): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Pick<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask, "name" | "description" | "project" | "identifier" | "data" | "status" | "runsAt" | "dateAborted" | "executionResults" | "executor" | "lastTriedAt" | "remainingNumberOfTries" | "numberOfTried"> & {
|
|
40
|
+
expires?: never;
|
|
21
41
|
} & {
|
|
22
42
|
_id: import("mongoose").Types.ObjectId;
|
|
23
43
|
} & {
|
|
24
44
|
__v: number;
|
|
25
|
-
}, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> &
|
|
26
|
-
expires?:
|
|
45
|
+
}, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Pick<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask, "name" | "description" | "project" | "identifier" | "data" | "status" | "runsAt" | "dateAborted" | "executionResults" | "executor" | "lastTriedAt" | "remainingNumberOfTries" | "numberOfTried"> & {
|
|
46
|
+
expires?: never;
|
|
27
47
|
} & {
|
|
28
48
|
_id: import("mongoose").Types.ObjectId;
|
|
29
49
|
} & {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.AdminTaskRepo = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
4
8
|
const factory_1 = require("../factory");
|
|
5
9
|
const settings_1 = require("../settings");
|
|
6
10
|
const task_1 = require("./mongoose/schemas/task");
|
|
7
11
|
const AVAILABLE_PROJECT_FIELDS = [
|
|
8
|
-
'alternateName',
|
|
9
12
|
'identifier',
|
|
10
13
|
'description',
|
|
11
14
|
'project',
|
|
@@ -19,7 +22,7 @@ const AVAILABLE_PROJECT_FIELDS = [
|
|
|
19
22
|
'executor',
|
|
20
23
|
'data',
|
|
21
24
|
'dateAborted',
|
|
22
|
-
'expires'
|
|
25
|
+
// 'expires' // 非同期アクションは移行につきexpires廃止(2026-08-05~)
|
|
23
26
|
];
|
|
24
27
|
/**
|
|
25
28
|
* タスク管理リポジトリ
|
|
@@ -99,10 +102,6 @@ class AdminTaskRepo {
|
|
|
99
102
|
if (typeof objectPurposeOrderNumberEq === 'string') {
|
|
100
103
|
andConditions.push({ 'data.purpose.orderNumber': { $exists: true, $eq: objectPurposeOrderNumberEq } });
|
|
101
104
|
}
|
|
102
|
-
const alternateNameRegex = params.alternateName?.$regex;
|
|
103
|
-
if (typeof alternateNameRegex === 'string' && alternateNameRegex.length > 0) {
|
|
104
|
-
andConditions.push({ alternateName: { $exists: true, $regex: new RegExp(alternateNameRegex) } });
|
|
105
|
-
}
|
|
106
105
|
const identifierRegex = params.identifier?.$regex;
|
|
107
106
|
if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
|
|
108
107
|
andConditions.push({ identifier: { $exists: true, $regex: new RegExp(identifierRegex) } });
|
|
@@ -150,6 +149,42 @@ class AdminTaskRepo {
|
|
|
150
149
|
.lean() // lean(2024-09-26~)
|
|
151
150
|
.exec();
|
|
152
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* cron:notifyLatency専用
|
|
154
|
+
*/
|
|
155
|
+
async countDelayedTasks(params) {
|
|
156
|
+
const { limit } = params;
|
|
157
|
+
const runsAtLt = (0, moment_1.default)()
|
|
158
|
+
.add(-params.delayInSeconds, 'seconds')
|
|
159
|
+
.toDate();
|
|
160
|
+
const query = this.taskModel.countDocuments({
|
|
161
|
+
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
162
|
+
runsAt: { $lt: runsAtLt },
|
|
163
|
+
...(Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined
|
|
164
|
+
});
|
|
165
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
166
|
+
query.limit(limit);
|
|
167
|
+
}
|
|
168
|
+
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
169
|
+
.exec();
|
|
170
|
+
return { count };
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 不要なタスクを削除する
|
|
174
|
+
*/
|
|
175
|
+
async deleteRunsAtPassedCertainPeriod(params) {
|
|
176
|
+
return this.taskModel.deleteMany({
|
|
177
|
+
runsAt: { $lt: params.runsAt.$lt },
|
|
178
|
+
status: {
|
|
179
|
+
$in: [
|
|
180
|
+
factory_1.factory.taskStatus.Aborted,
|
|
181
|
+
factory_1.factory.taskStatus.Executed,
|
|
182
|
+
// factory.taskStatus.Expired // discontinue(2026-08-06~)
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
.exec();
|
|
187
|
+
}
|
|
153
188
|
getCursor(conditions, projection) {
|
|
154
189
|
return this.taskModel.find(conditions, projection)
|
|
155
190
|
.sort({ runsAt: factory_1.factory.sortType.Ascending })
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
import { factory } from '../factory';
|
|
3
|
+
interface IAggregationByStatus {
|
|
4
|
+
taskCount: number;
|
|
5
|
+
avgLatency: number;
|
|
6
|
+
maxLatency: number;
|
|
7
|
+
minLatency: number;
|
|
8
|
+
percentilesLatency: {
|
|
9
|
+
name: string;
|
|
10
|
+
value: number;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
13
|
+
interface IStatus {
|
|
14
|
+
status: factory.taskStatus;
|
|
15
|
+
aggregation: IAggregationByStatus;
|
|
16
|
+
}
|
|
17
|
+
interface IAggregateTask {
|
|
18
|
+
statuses: IStatus[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 予定タスク集計リポジトリ
|
|
22
|
+
*/
|
|
23
|
+
export declare class AggregateScheduledTaskRepo {
|
|
24
|
+
private readonly scheduledTaskModel;
|
|
25
|
+
constructor(connection: Connection);
|
|
26
|
+
aggregateScheduledTask(params: {
|
|
27
|
+
runsFrom: Date;
|
|
28
|
+
runsThrough: Date;
|
|
29
|
+
}): Promise<IAggregateTask>;
|
|
30
|
+
private agggregateByStatus;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AggregateScheduledTaskRepo = void 0;
|
|
4
|
+
const factory_1 = require("../factory");
|
|
5
|
+
const scheduledTasks_1 = require("./mongoose/schemas/scheduledTasks");
|
|
6
|
+
/**
|
|
7
|
+
* 予定タスク集計リポジトリ
|
|
8
|
+
*/
|
|
9
|
+
class AggregateScheduledTaskRepo {
|
|
10
|
+
scheduledTaskModel;
|
|
11
|
+
constructor(connection) {
|
|
12
|
+
this.scheduledTaskModel = connection.model(scheduledTasks_1.modelName, (0, scheduledTasks_1.createSchema)());
|
|
13
|
+
}
|
|
14
|
+
async aggregateScheduledTask(params) {
|
|
15
|
+
const statuses = await Promise.all([
|
|
16
|
+
factory_1.factory.taskStatus.Executed,
|
|
17
|
+
factory_1.factory.taskStatus.Aborted
|
|
18
|
+
].map(async (taskStatus) => {
|
|
19
|
+
const matchConditions = {
|
|
20
|
+
status: { $eq: taskStatus },
|
|
21
|
+
runsAt: {
|
|
22
|
+
$gte: params.runsFrom,
|
|
23
|
+
$lte: params.runsThrough
|
|
24
|
+
},
|
|
25
|
+
// ...(typeof params.project?.id?.$ne === 'string')
|
|
26
|
+
// ? { 'project.id': { $ne: params.project.id.$ne } }
|
|
27
|
+
// : undefined
|
|
28
|
+
};
|
|
29
|
+
return this.agggregateByStatus({ matchConditions, status: taskStatus });
|
|
30
|
+
}));
|
|
31
|
+
return { statuses };
|
|
32
|
+
}
|
|
33
|
+
async agggregateByStatus(params) {
|
|
34
|
+
const matchConditions = params.matchConditions;
|
|
35
|
+
const taskStatus = params.status;
|
|
36
|
+
const aggregate1 = this.scheduledTaskModel.aggregate([
|
|
37
|
+
{
|
|
38
|
+
$match: matchConditions
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
$project: {
|
|
42
|
+
latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
|
|
43
|
+
status: '$status',
|
|
44
|
+
runsAt: '$runsAt',
|
|
45
|
+
lastTriedAt: '$lastTriedAt'
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
$group: {
|
|
50
|
+
_id: '$status',
|
|
51
|
+
taskCount: { $sum: 1 },
|
|
52
|
+
maxLatency: { $max: '$latency' },
|
|
53
|
+
minLatency: { $min: '$latency' },
|
|
54
|
+
avgLatency: { $avg: '$latency' }
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
$project: {
|
|
59
|
+
_id: 0,
|
|
60
|
+
taskCount: '$taskCount',
|
|
61
|
+
avgLatency: '$avgLatency',
|
|
62
|
+
maxLatency: '$maxLatency',
|
|
63
|
+
minLatency: '$minLatency'
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
]);
|
|
67
|
+
// const explainResult = await aggregate1.explain();
|
|
68
|
+
// console.dir(explainResult, { depth: null });
|
|
69
|
+
// return;
|
|
70
|
+
const aggregations = await aggregate1.exec();
|
|
71
|
+
const percents = [50, 95, 99];
|
|
72
|
+
if (aggregations.length === 0) {
|
|
73
|
+
return {
|
|
74
|
+
status: taskStatus,
|
|
75
|
+
aggregation: {
|
|
76
|
+
taskCount: 0,
|
|
77
|
+
avgLatency: 0,
|
|
78
|
+
maxLatency: 0,
|
|
79
|
+
minLatency: 0,
|
|
80
|
+
percentilesLatency: percents.map((percent) => {
|
|
81
|
+
return {
|
|
82
|
+
name: String(percent),
|
|
83
|
+
value: 0
|
|
84
|
+
};
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const ranks4percentile = percents.map((percentile) => {
|
|
90
|
+
return {
|
|
91
|
+
percentile,
|
|
92
|
+
rank: Math.floor(aggregations[0].taskCount * percentile / 100)
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
const aggregate2 = this.scheduledTaskModel.aggregate([
|
|
96
|
+
{
|
|
97
|
+
$match: matchConditions
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
$project: {
|
|
101
|
+
latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
|
|
102
|
+
status: '$status',
|
|
103
|
+
runsAt: '$runsAt',
|
|
104
|
+
lastTriedAt: '$lastTriedAt'
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{ $sort: { latency: 1 } },
|
|
108
|
+
{
|
|
109
|
+
$group: {
|
|
110
|
+
_id: '$status',
|
|
111
|
+
latencies: { $push: '$latency' }
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
$project: {
|
|
116
|
+
_id: 0,
|
|
117
|
+
percentilesLatency: ranks4percentile.map((rank) => {
|
|
118
|
+
return {
|
|
119
|
+
name: String(rank.percentile),
|
|
120
|
+
value: { $arrayElemAt: ['$latencies', rank.rank] }
|
|
121
|
+
};
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
]);
|
|
126
|
+
const aggregations2 = await aggregate2.exec();
|
|
127
|
+
return {
|
|
128
|
+
status: taskStatus,
|
|
129
|
+
aggregation: {
|
|
130
|
+
...aggregations[0],
|
|
131
|
+
...aggregations2[0]
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.AggregateScheduledTaskRepo = AggregateScheduledTaskRepo;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Connection } from 'mongoose';
|
|
2
2
|
import { factory } from '../factory';
|
|
3
|
-
import {
|
|
3
|
+
import { IDocType } from './mongoose/schemas/asyncAction';
|
|
4
4
|
import type { IExecutableTask } from '../taskSettings';
|
|
5
5
|
type ISavingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'executionResults' | 'name' | 'project' | 'runsAt' | 'status'> & {
|
|
6
6
|
expires: Date;
|
|
@@ -11,7 +11,7 @@ type IKeyOfProjection = keyof factory.task.ITask<factory.taskName> | 'expires';
|
|
|
11
11
|
* 非同期アクションリポジトリ
|
|
12
12
|
*/
|
|
13
13
|
export declare class AsyncActionRepo {
|
|
14
|
-
readonly asyncActionModel
|
|
14
|
+
private readonly asyncActionModel;
|
|
15
15
|
constructor(connection: Connection);
|
|
16
16
|
/**
|
|
17
17
|
* Readyタスクをひとつ追加する
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
2
|
import { IVirtuals } from '../virtuals';
|
|
3
3
|
import { factory } from '../../../factory';
|
|
4
|
-
type IDocType =
|
|
5
|
-
|
|
6
|
-
* 非同期アクション移行前のタスクには残っている(2026-07-29時点)
|
|
7
|
-
*/
|
|
8
|
-
expires?: Date;
|
|
4
|
+
type IDocType = Pick<factory.task.ITask<factory.taskName>, 'data' | 'dateAborted' | 'description' | 'executionResults' | 'executor' | 'identifier' | 'lastTriedAt' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'> & {
|
|
5
|
+
expires?: never;
|
|
9
6
|
};
|
|
10
7
|
type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
|
|
11
8
|
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
@@ -8,7 +8,6 @@ const settings_1 = require("../../../settings");
|
|
|
8
8
|
const modelName = 'Task';
|
|
9
9
|
exports.modelName = modelName;
|
|
10
10
|
const schemaDefinition = {
|
|
11
|
-
alternateName: String, // add(2025-03-28~)
|
|
12
11
|
identifier: String,
|
|
13
12
|
description: String, // add(2025-03-30~)
|
|
14
13
|
project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
@@ -22,7 +21,8 @@ const schemaDefinition = {
|
|
|
22
21
|
executor: mongoose_1.SchemaTypes.Mixed,
|
|
23
22
|
data: mongoose_1.SchemaTypes.Mixed,
|
|
24
23
|
dateAborted: Date,
|
|
25
|
-
|
|
24
|
+
// alternateName: String, // add(2025-03-28~) // identidfier移行完了につき廃止(2026-08-07~)
|
|
25
|
+
// expires: Date // add(2024-04-23~) // 非同期アクションは移行につきexpires廃止(2026-08-05~)
|
|
26
26
|
};
|
|
27
27
|
const schemaOptions = {
|
|
28
28
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -93,15 +93,6 @@ const indexes = [
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
],
|
|
96
|
-
[
|
|
97
|
-
{ expires: 1, runsAt: -1 },
|
|
98
|
-
{
|
|
99
|
-
name: 'expires',
|
|
100
|
-
partialFilterExpression: {
|
|
101
|
-
expires: { $exists: true }
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
],
|
|
105
96
|
[
|
|
106
97
|
{ remainingNumberOfTries: 1, runsAt: -1 },
|
|
107
98
|
{ name: 'searchByRemainingNumberOfTries-v2' }
|
|
@@ -177,6 +168,10 @@ const indexes = [
|
|
|
177
168
|
{ status: 1, runsAt: 1, name: 1 },
|
|
178
169
|
{ name: 'executeOneByNameIfExists' } // add(2025-03-08~)
|
|
179
170
|
],
|
|
171
|
+
[
|
|
172
|
+
{ status: 1, name: 1, runsAt: 1 },
|
|
173
|
+
{ name: 'runDelayedTaskByName' } // add(2026-08-05~)
|
|
174
|
+
],
|
|
180
175
|
[
|
|
181
176
|
{ status: 1, remainingNumberOfTries: 1, lastTriedAt: 1 },
|
|
182
177
|
{
|
|
@@ -195,26 +190,6 @@ const indexes = [
|
|
|
195
190
|
}
|
|
196
191
|
}
|
|
197
192
|
],
|
|
198
|
-
[
|
|
199
|
-
{ status: 1, expires: 1 },
|
|
200
|
-
{
|
|
201
|
-
name: 'makeExpiredMany',
|
|
202
|
-
partialFilterExpression: {
|
|
203
|
-
expires: { $exists: true }
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
],
|
|
207
|
-
[
|
|
208
|
-
// add unique index(2025-03-28~)
|
|
209
|
-
{ alternateName: 1 },
|
|
210
|
-
{
|
|
211
|
-
unique: true,
|
|
212
|
-
name: 'uniqueAlternateName',
|
|
213
|
-
partialFilterExpression: {
|
|
214
|
-
alternateName: { $exists: true }
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
],
|
|
218
193
|
// add unique index(dev)(2025-03-28~)
|
|
219
194
|
// add unique index(test,prod)(2026-07-08~)
|
|
220
195
|
[
|
|
@@ -226,7 +201,21 @@ const indexes = [
|
|
|
226
201
|
identifier: { $exists: true }
|
|
227
202
|
}
|
|
228
203
|
}
|
|
229
|
-
]
|
|
204
|
+
],
|
|
205
|
+
// alternateNameへのインデックスはおそらくもう不要(2026-08-07~)
|
|
206
|
+
// dev,testではインデックス削除済(2026-08-07)
|
|
207
|
+
// prodでは削除予定(2026-08-??)
|
|
208
|
+
// [
|
|
209
|
+
// // add unique index(2025-03-28~)
|
|
210
|
+
// { alternateName: 1 },
|
|
211
|
+
// {
|
|
212
|
+
// unique: true,
|
|
213
|
+
// name: 'uniqueAlternateName',
|
|
214
|
+
// partialFilterExpression: {
|
|
215
|
+
// alternateName: { $exists: true }
|
|
216
|
+
// }
|
|
217
|
+
// }
|
|
218
|
+
// ],
|
|
230
219
|
];
|
|
231
220
|
exports.indexes = indexes;
|
|
232
221
|
/**
|
|
@@ -79,7 +79,6 @@ export interface IPaymentMethodByPaymentUrl {
|
|
|
79
79
|
*/
|
|
80
80
|
export declare class OrderInTransactionRepo extends AcceptedOfferInReserveRepo {
|
|
81
81
|
private readonly orderModel;
|
|
82
|
-
private readonly transactionModel;
|
|
83
82
|
constructor(connection: Connection);
|
|
84
83
|
createPlaceOrderIfNotExists(params: Pick<IOrderInTransaction, 'orderNumber' | 'project' | 'identifier' | 'broker' | 'seller' | 'customer'>): Promise<import("mongoose").UpdateWriteOpResult | undefined>;
|
|
85
84
|
/**
|
|
@@ -177,8 +176,6 @@ export declare class OrderInTransactionRepo extends AcceptedOfferInReserveRepo {
|
|
|
177
176
|
savePaymentMethodId(params: {
|
|
178
177
|
id: string;
|
|
179
178
|
paymentMethod: IPaymentMethodByPaymentUrl;
|
|
180
|
-
}, options: {
|
|
181
|
-
savePaymentMethodIdInTransaction: boolean;
|
|
182
179
|
}): Promise<void>;
|
|
183
180
|
/**
|
|
184
181
|
* 進行中取引に保管された採用済決済方法を検索する
|
|
@@ -5,7 +5,11 @@ exports.OrderInTransactionRepo = void 0;
|
|
|
5
5
|
const errorHandler_1 = require("../errorHandler");
|
|
6
6
|
const factory_1 = require("../factory");
|
|
7
7
|
const order_1 = require("./mongoose/schemas/order");
|
|
8
|
-
|
|
8
|
+
// import {
|
|
9
|
+
// createSchema as createTransactionSchema,
|
|
10
|
+
// IModel as ITransactionModel, modelName as transactionModelName,
|
|
11
|
+
// IDocType as ITransactionDocType
|
|
12
|
+
// } from './mongoose/schemas/transaction';
|
|
9
13
|
const acceptedOfferInReserve_1 = require("./acceptedOfferInReserve");
|
|
10
14
|
// const debug = createDebug('chevre-domain:repo:orderInTransaction');
|
|
11
15
|
/**
|
|
@@ -13,11 +17,11 @@ const acceptedOfferInReserve_1 = require("./acceptedOfferInReserve");
|
|
|
13
17
|
*/
|
|
14
18
|
class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInReserveRepo {
|
|
15
19
|
orderModel;
|
|
16
|
-
transactionModel;
|
|
20
|
+
// private readonly transactionModel: ITransactionModel;
|
|
17
21
|
constructor(connection) {
|
|
18
22
|
super(connection);
|
|
19
23
|
this.orderModel = connection.model(order_1.modelName, (0, order_1.createSchema)());
|
|
20
|
-
this.transactionModel = connection.model
|
|
24
|
+
// this.transactionModel = connection.model<ITransactionDocType, ITransactionModel>(transactionModelName, createTransactionSchema());
|
|
21
25
|
}
|
|
22
26
|
async createPlaceOrderIfNotExists(params) {
|
|
23
27
|
const { orderNumber, project, identifier, broker, seller, customer } = params;
|
|
@@ -284,29 +288,33 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
284
288
|
* 特定の進行中取引の決済方法IDを保管する
|
|
285
289
|
* transactionsへの保管としてひとまず定義(2026-07-11~)
|
|
286
290
|
*/
|
|
287
|
-
async savePaymentMethodId(params
|
|
288
|
-
const { savePaymentMethodIdInTransaction } = options;
|
|
291
|
+
async savePaymentMethodId(params) {
|
|
289
292
|
const { paymentMethodId } = params.paymentMethod;
|
|
290
293
|
if (typeof paymentMethodId !== 'string' || paymentMethodId === '') {
|
|
291
294
|
throw new factory_1.factory.errors.ArgumentNull('paymentMethod.paymentMethodId');
|
|
292
295
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
296
|
+
// savePaymentMethodIdInTransactionは廃止(2026-08-04~)
|
|
297
|
+
// if (savePaymentMethodIdInTransaction) {
|
|
298
|
+
// await this.transactionModel.findOneAndUpdate(
|
|
299
|
+
// {
|
|
300
|
+
// _id: { $eq: params.id },
|
|
301
|
+
// status: { $eq: factory.transactionStatusType.InProgress }
|
|
302
|
+
// },
|
|
303
|
+
// {
|
|
304
|
+
// $set: { 'object.paymentMethods': { paymentMethodId } }
|
|
305
|
+
// },
|
|
306
|
+
// {
|
|
307
|
+
// projection: { _id: 1 }
|
|
308
|
+
// }
|
|
309
|
+
// )
|
|
310
|
+
// .lean<{ _id: ObjectId }>()
|
|
311
|
+
// .exec()
|
|
312
|
+
// .then((doc) => {
|
|
313
|
+
// if (doc === null) {
|
|
314
|
+
// throw new factory.errors.NotFound(factory.transactionType.PlaceOrder);
|
|
315
|
+
// }
|
|
316
|
+
// });
|
|
317
|
+
// }
|
|
310
318
|
// 注文ドキュメントにも保管する(2026-07-12~)
|
|
311
319
|
await this.orderModel.findOneAndUpdate({
|
|
312
320
|
identifier: { $eq: params.id },
|