@chevre/domain
Version:
Chevre Domain Library for Node.js
300 lines (299 loc) • 12.4 kB
TypeScript
import type { AnyKeys, Connection, FilterQuery, ProjectionType, UpdateWriteOpResult } from 'mongoose';
import { INextFunction } from '../eventEmitter/task';
import * as factory from '../factory';
import { IModel } from './mongoose/schemas/task';
interface IAggregationByStatus {
taskCount: number;
avgLatency: number;
maxLatency: number;
minLatency: number;
percentilesLatency: {
name: string;
value: number;
}[];
}
interface IStatus {
status: factory.taskStatus;
aggregation: IAggregationByStatus;
}
export interface IAggregateTask {
statuses: IStatus[];
}
interface IOptionOnCreate {
emitImmediately: boolean;
}
export type IExecutableTaskKeys = 'data' | 'id' | 'name' | 'status' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'expires';
export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys>;
type IKeyOfProjection = keyof factory.task.ITask<factory.taskName>;
type ICreatingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status' | 'identifier' | 'description'>;
/**
* タスクリポジトリ
*/
export declare class TaskRepo {
readonly taskModel: IModel;
constructor(connection: Connection);
static CREATE_MONGO_CONDITIONS(params: factory.task.ISearchConditions): FilterQuery<import("@chevre/factory/lib/task").ITask | import("@chevre/factory/lib/task/confirmMoneyTransfer").ITask | import("@chevre/factory/lib/task/confirmRegisterService").ITask | import("@chevre/factory/lib/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/task/createAccountingReport").ITask | import("@chevre/factory/lib/task/createEvent").ITask | import("@chevre/factory/lib/task/deletePerson").ITask | import("@chevre/factory/lib/task/deleteTransaction").ITask | import("@chevre/factory/lib/task/givePointAward").ITask | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/task/onEventChanged").ITask | import("@chevre/factory/lib/task/onResourceUpdated").ITask | import("@chevre/factory/lib/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/task/placeOrder").ITask | import("@chevre/factory/lib/task/returnOrder").ITask | import("@chevre/factory/lib/task/returnMoneyTransfer").ITask | import("@chevre/factory/lib/task/returnPayTransaction").ITask | import("@chevre/factory/lib/task/returnPointAward").ITask | import("@chevre/factory/lib/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/task/sendEmailMessage").ITask | import("@chevre/factory/lib/task/sendOrder").ITask | import("@chevre/factory/lib/task/triggerWebhook").ITask | import("@chevre/factory/lib/task/useReservation").ITask | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").ITask | import("@chevre/factory/lib/task/voidPayTransaction").ITask | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/voidReserveTransaction").ITask>[];
runImmediately(params: Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'expires' | 'name' | 'project' | 'remainingNumberOfTries' | 'runsAt'> & {
alternateName?: never;
identifier?: never;
expires: Date;
}, next: INextFunction): Promise<{
id: string;
}>;
saveMany(taskAttributes: ICreatingTask[], options: IOptionOnCreate): Promise<{
id: string;
}[]>;
/**
* タスク識別子から検索する
*/
findByIdentifier(params: {
identifier: string;
name: factory.taskName;
project: {
id: string;
};
}): Promise<{
id: string;
status: factory.taskStatus;
} | undefined>;
/**
* タスク識別子から冪等作成する
* reimplement createIfNotExistByIdentifier(2025-03-28~)
*/
createIfNotExistByAlternateName(params: ICreatingTask & {
alternateName: string;
}, options: IOptionOnCreate): Promise<void>;
/**
* 取引削除タスク冪等作成
*/
createDeleteTransactionTaskIfNotExist(params: Pick<factory.task.IAttributes<factory.taskName.DeleteTransaction>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'>, options: IOptionOnCreate): Promise<void>;
createOnAssetTransactionStatusChangedTaskIfNotExist(params: Pick<factory.task.IAttributes<factory.taskName.OnAssetTransactionStatusChanged>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'>, options: IOptionOnCreate): Promise<void>;
executeOneById(params: {
id: string;
status: factory.taskStatus.Ready | factory.taskStatus.Running;
executor: {
name: string;
};
expires?: Date;
}): Promise<IExecutableTask<factory.taskName> | null>;
/**
* support no name(2025-03-04~)
*/
executeOneIfExists(params: {
name?: {
$eq?: factory.taskName;
$nin?: factory.taskName[];
};
executor: {
name: string;
};
runsAt: {
$lt: Date;
};
}): Promise<IExecutableTask<factory.taskName> | null>;
/**
* add(2025-03-16~)
*/
countPotentiallyRunning(params: {
name?: {
$eq?: factory.taskName;
$nin?: factory.taskName[];
};
runsAt: {
$lt: Date;
};
limit?: number;
}): Promise<{
count: number;
}>;
emitRunningIfExists(params: {
name?: {
$eq?: factory.taskName;
$nin?: factory.taskName[];
};
executor: {
name: string;
};
runsAt: {
$lt: Date;
};
sort: {
numberOfTried?: factory.sortType;
runsAt: factory.sortType;
};
}): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
findExecutableOne(params: {
name?: {
$eq?: factory.taskName;
$nin?: factory.taskName[];
};
runsAt: {
$lt: Date;
};
}): Promise<IExecutableTask<factory.taskName> | null>;
/**
* emit OnTaskStatusChanged on delayed tasks
*/
/**
* make tasks expired
*/
makeExpiredMany(params: {
expiresLt: Date;
}): Promise<UpdateWriteOpResult>;
/**
* 実行中ステータスのままになっているタスクをリトライする
*/
retry(params: {
intervalInMinutes: number;
}): Promise<UpdateWriteOpResult>;
/**
* 実行中止済タスクを強制的にリトライ
* 中止済タスクでなければ何もしない
*/
retryForciblyIfAborted(params: {
id: string;
remainingNumberOfTries: number;
}): Promise<UpdateWriteOpResult>;
abortOne(params: {
intervalInMinutes: number;
}): Promise<factory.task.ITask<factory.taskName> | null>;
abortMany(params: {
intervalInMinutes: number;
}): Promise<UpdateWriteOpResult>;
/**
* 実行結果を保管する
*/
pushExecutionResultById(params: {
/**
* タスクID
*/
id: string;
status: factory.taskStatus;
}, executionResult: factory.task.IExecutionResult, next?: INextFunction): Promise<void>;
/**
* 特定タスク検索
*/
count(params: factory.task.ISearchConditions): Promise<{
count: number;
}>;
/**
* 検索する
*/
projectFields(params: factory.task.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.task.ITask<factory.taskName>[]>;
deleteByProject(params: {
project: {
id: string;
};
}): Promise<void>;
deleteByName(params: {
name: factory.taskName;
status?: {
$eq?: factory.taskStatus;
};
runsAt?: {
$gte: Date;
$lte: Date;
};
}): Promise<import("mongodb").DeleteResult>;
/**
* 不要なタスクを削除する
*/
deleteRunsAtPassedCertainPeriod(params: {
runsAt: {
$lt: Date;
};
}): Promise<import("mongodb").DeleteResult>;
countDelayedTasks(params: {
delayInSeconds: number;
name: {
$nin?: factory.taskName[];
};
limit?: number;
}): Promise<{
count: number;
}>;
getCursor(conditions: FilterQuery<factory.task.ITask<factory.taskName>>, projection: ProjectionType<factory.task.ITask<factory.taskName>>): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
alternateName?: string | undefined;
identifier?: string | undefined;
description?: string | undefined;
project: Pick<factory.project.IProject, "id" | "typeOf">;
name: factory.taskName;
status: factory.taskStatus;
runsAt: Date;
remainingNumberOfTries: number;
lastTriedAt?: Date | undefined;
numberOfTried: number;
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
data: import("@chevre/factory/lib/task").IData;
dateAborted?: Date | undefined;
expires?: Date | undefined;
}> & {
alternateName?: string | undefined;
identifier?: string | undefined;
description?: string | undefined;
project: Pick<factory.project.IProject, "id" | "typeOf">;
name: factory.taskName;
status: factory.taskStatus;
runsAt: Date;
remainingNumberOfTries: number;
lastTriedAt?: Date | undefined;
numberOfTried: number;
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
data: import("@chevre/factory/lib/task").IData;
dateAborted?: Date | undefined;
expires?: Date | undefined;
} & {
_id: import("mongoose").Types.ObjectId;
}, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, {
alternateName?: string | undefined;
identifier?: string | undefined;
description?: string | undefined;
project: Pick<factory.project.IProject, "id" | "typeOf">;
name: factory.taskName;
status: factory.taskStatus;
runsAt: Date;
remainingNumberOfTries: number;
lastTriedAt?: Date | undefined;
numberOfTried: number;
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
data: import("@chevre/factory/lib/task").IData;
dateAborted?: Date | undefined;
expires?: Date | undefined;
}> & {
alternateName?: string | undefined;
identifier?: string | undefined;
description?: string | undefined;
project: Pick<factory.project.IProject, "id" | "typeOf">;
name: factory.taskName;
status: factory.taskStatus;
runsAt: Date;
remainingNumberOfTries: number;
lastTriedAt?: Date | undefined;
numberOfTried: number;
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
data: import("@chevre/factory/lib/task").IData;
dateAborted?: Date | undefined;
expires?: Date | undefined;
} & {
_id: import("mongoose").Types.ObjectId;
}>>;
unsetUnnecessaryFields(params: {
filter: FilterQuery<factory.task.ITask<factory.taskName>>;
$unset: AnyKeys<factory.task.ITask<factory.taskName>>;
}): Promise<UpdateWriteOpResult>;
aggregateTask(params: {
project?: {
id?: {
$ne?: string;
};
};
runsFrom: Date;
runsThrough: Date;
}): Promise<IAggregateTask>;
private agggregateByStatus;
}
export {};