@chevre/domain 26.0.0-alpha.2 → 26.0.0-alpha.21
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 +31 -8
- package/lib/chevre/repo/adminTask.js +41 -26
- 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 +87 -96
- 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 +74 -0
- package/lib/chevre/repo/taskDelayed.js +195 -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,29 +1,52 @@
|
|
|
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
|
+
type IFindParams = factory.task.ISearchConditions & {
|
|
6
|
+
data?: never;
|
|
7
|
+
};
|
|
5
8
|
/**
|
|
6
9
|
* タスク管理リポジトリ
|
|
7
10
|
*/
|
|
8
11
|
export declare class AdminTaskRepo {
|
|
9
12
|
private readonly taskModel;
|
|
10
13
|
constructor(connection: Connection);
|
|
11
|
-
static CREATE_MONGO_CONDITIONS(params:
|
|
12
|
-
countTasks(params:
|
|
14
|
+
static CREATE_MONGO_CONDITIONS(params: IFindParams): 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
|
+
countTasks(params: IFindParams): Promise<{
|
|
13
16
|
count: number;
|
|
14
17
|
}>;
|
|
15
18
|
/**
|
|
16
19
|
* 検索する
|
|
17
20
|
*/
|
|
18
|
-
findTasks(params:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
findTasks(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<factory.task.ITask<factory.taskName>[]>;
|
|
22
|
+
/**
|
|
23
|
+
* cron:notifyLatency専用
|
|
24
|
+
*/
|
|
25
|
+
countDelayedTasks(params: {
|
|
26
|
+
delayInSeconds: number;
|
|
27
|
+
name: {
|
|
28
|
+
$nin?: factory.taskName[];
|
|
29
|
+
};
|
|
30
|
+
limit?: number;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
count: number;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* 不要なタスクを削除する
|
|
36
|
+
*/
|
|
37
|
+
deleteRunsAtPassedCertainPeriod(params: {
|
|
38
|
+
runsAt: {
|
|
39
|
+
$lt: Date;
|
|
40
|
+
};
|
|
41
|
+
}): Promise<import("mongodb").DeleteResult>;
|
|
42
|
+
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"> & {
|
|
43
|
+
expires?: never;
|
|
21
44
|
} & {
|
|
22
45
|
_id: import("mongoose").Types.ObjectId;
|
|
23
46
|
} & {
|
|
24
47
|
__v: number;
|
|
25
|
-
}, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> &
|
|
26
|
-
expires?:
|
|
48
|
+
}, 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"> & {
|
|
49
|
+
expires?: never;
|
|
27
50
|
} & {
|
|
28
51
|
_id: import("mongoose").Types.ObjectId;
|
|
29
52
|
} & {
|
|
@@ -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
|
* タスク管理リポジトリ
|
|
@@ -79,30 +82,6 @@ class AdminTaskRepo {
|
|
|
79
82
|
if (dateAbortedLte instanceof Date) {
|
|
80
83
|
andConditions.push({ dateAborted: { $type: 'date', $lte: dateAbortedLte } });
|
|
81
84
|
}
|
|
82
|
-
const objectIdEq = params.data?.object?.id?.$eq;
|
|
83
|
-
if (typeof objectIdEq === 'string') {
|
|
84
|
-
andConditions.push({ 'data.object.id': { $exists: true, $eq: objectIdEq } });
|
|
85
|
-
}
|
|
86
|
-
const objectOrderNumberEq = params.data?.object?.orderNumber?.$eq;
|
|
87
|
-
if (typeof objectOrderNumberEq === 'string') {
|
|
88
|
-
andConditions.push({ 'data.object.orderNumber': { $exists: true, $eq: objectOrderNumberEq } });
|
|
89
|
-
}
|
|
90
|
-
const objectTransactionNumberEq = params.data?.object?.transactionNumber?.$eq;
|
|
91
|
-
if (typeof objectTransactionNumberEq === 'string') {
|
|
92
|
-
andConditions.push({ 'data.object.transactionNumber': { $exists: true, $eq: objectTransactionNumberEq } });
|
|
93
|
-
}
|
|
94
|
-
const objectPurposeIdEq = params.data?.purpose?.id?.$eq;
|
|
95
|
-
if (typeof objectPurposeIdEq === 'string') {
|
|
96
|
-
andConditions.push({ 'data.purpose.id': { $exists: true, $eq: objectPurposeIdEq } });
|
|
97
|
-
}
|
|
98
|
-
const objectPurposeOrderNumberEq = params.data?.purpose?.orderNumber?.$eq;
|
|
99
|
-
if (typeof objectPurposeOrderNumberEq === 'string') {
|
|
100
|
-
andConditions.push({ 'data.purpose.orderNumber': { $exists: true, $eq: objectPurposeOrderNumberEq } });
|
|
101
|
-
}
|
|
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
85
|
const identifierRegex = params.identifier?.$regex;
|
|
107
86
|
if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
|
|
108
87
|
andConditions.push({ identifier: { $exists: true, $regex: new RegExp(identifierRegex) } });
|
|
@@ -150,6 +129,42 @@ class AdminTaskRepo {
|
|
|
150
129
|
.lean() // lean(2024-09-26~)
|
|
151
130
|
.exec();
|
|
152
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* cron:notifyLatency専用
|
|
134
|
+
*/
|
|
135
|
+
async countDelayedTasks(params) {
|
|
136
|
+
const { limit } = params;
|
|
137
|
+
const runsAtLt = (0, moment_1.default)()
|
|
138
|
+
.add(-params.delayInSeconds, 'seconds')
|
|
139
|
+
.toDate();
|
|
140
|
+
const query = this.taskModel.countDocuments({
|
|
141
|
+
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
142
|
+
runsAt: { $lt: runsAtLt },
|
|
143
|
+
...(Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined
|
|
144
|
+
});
|
|
145
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
146
|
+
query.limit(limit);
|
|
147
|
+
}
|
|
148
|
+
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
149
|
+
.exec();
|
|
150
|
+
return { count };
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 不要なタスクを削除する
|
|
154
|
+
*/
|
|
155
|
+
async deleteRunsAtPassedCertainPeriod(params) {
|
|
156
|
+
return this.taskModel.deleteMany({
|
|
157
|
+
runsAt: { $lt: params.runsAt.$lt },
|
|
158
|
+
status: {
|
|
159
|
+
$in: [
|
|
160
|
+
factory_1.factory.taskStatus.Aborted,
|
|
161
|
+
factory_1.factory.taskStatus.Executed,
|
|
162
|
+
// factory.taskStatus.Expired // discontinue(2026-08-06~)
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
.exec();
|
|
167
|
+
}
|
|
153
168
|
getCursor(conditions, projection) {
|
|
154
169
|
return this.taskModel.find(conditions, projection)
|
|
155
170
|
.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>;
|