@chevre/domain 22.11.0-alpha.12 → 22.11.0-alpha.14
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/notifyAbortedTasksByEmail.ts +1 -1
- package/example/src/regex.ts +31 -0
- package/lib/chevre/eventEmitter/task.d.ts +13 -3
- package/lib/chevre/repo/seller.d.ts +4 -4
- package/lib/chevre/repo/task.d.ts +27 -31
- package/lib/chevre/repo/task.js +54 -134
- package/lib/chevre/service/assetTransaction/cancelReservation/start.d.ts +1 -1
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +15 -0
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +38 -0
- package/lib/chevre/service/notification.d.ts +2 -1
- package/lib/chevre/service/notification.js +3 -1
- package/lib/chevre/service/task/acceptCOAOffer.d.ts +1 -1
- package/lib/chevre/service/task/aggregateOffers.d.ts +1 -1
- package/lib/chevre/service/task/aggregateOnSystem.d.ts +4 -2
- package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +1 -1
- package/lib/chevre/service/task/authorizePayment.d.ts +1 -1
- package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/cancelPendingReservation.d.ts +1 -1
- package/lib/chevre/service/task/cancelReservation.d.ts +1 -1
- package/lib/chevre/service/task/checkMovieTicket.d.ts +1 -1
- package/lib/chevre/service/task/checkResource.d.ts +1 -1
- package/lib/chevre/service/task/confirmMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/confirmPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterService.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/confirmReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/createAccountingReport.d.ts +1 -1
- package/lib/chevre/service/task/createEvent.d.ts +1 -1
- package/lib/chevre/service/task/deletePerson.d.ts +1 -1
- package/lib/chevre/service/task/deleteTransaction.d.ts +1 -1
- package/lib/chevre/service/task/givePointAward.d.ts +1 -1
- package/lib/chevre/service/task/handleNotification.d.ts +4 -2
- package/lib/chevre/service/task/importEventCapacitiesFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/importEventsFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/importOffersFromCOA.d.ts +1 -1
- package/lib/chevre/service/task/invalidatePaymentUrl.d.ts +1 -1
- package/lib/chevre/service/task/moneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +1 -1
- package/lib/chevre/service/task/onAuthorizationCreated.d.ts +1 -1
- package/lib/chevre/service/task/onEventChanged.d.ts +1 -1
- package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +1 -1
- package/lib/chevre/service/task/onResourceUpdated.d.ts +1 -1
- package/lib/chevre/service/task/pay.d.ts +1 -1
- package/lib/chevre/service/task/placeOrder.d.ts +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.d.ts +1 -1
- package/lib/chevre/service/task/refund.d.ts +1 -1
- package/lib/chevre/service/task/registerService.d.ts +1 -1
- package/lib/chevre/service/task/reserve.d.ts +1 -1
- package/lib/chevre/service/task/returnMoneyTransfer.d.ts +1 -1
- package/lib/chevre/service/task/returnOrder.d.ts +1 -1
- package/lib/chevre/service/task/returnPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/returnPointAward.d.ts +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task/sendEmailMessage.d.ts +1 -1
- package/lib/chevre/service/task/sendOrder.d.ts +1 -1
- package/lib/chevre/service/task/triggerWebhook.d.ts +1 -1
- package/lib/chevre/service/task/useReservation.d.ts +1 -1
- package/lib/chevre/service/task/voidMoneyTransferTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidPayTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidPayment.d.ts +1 -1
- package/lib/chevre/service/task/voidRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/voidReserveTransaction.d.ts +1 -1
- package/lib/chevre/service/task.d.ts +1 -23
- package/lib/chevre/service/task.js +3 -110
- package/lib/chevre/service/taskHandler.d.ts +26 -0
- package/lib/chevre/service/taskHandler.js +102 -0
- package/lib/chevre/settings/aggregation.d.ts +1 -1
- package/package.json +1 -1
|
@@ -30,7 +30,7 @@ async function main() {
|
|
|
30
30
|
]
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
const result = await (await chevre.service.
|
|
33
|
+
const result = await (await chevre.service.notification.createService()).notifyAbortedTasksByEmail({
|
|
34
34
|
dateAbortedGte: moment()
|
|
35
35
|
// tslint:disable-next-line:no-magic-numbers
|
|
36
36
|
.add(-10, 'days')
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
const projectIdMustBe = /^[0-9a-z-]+$/; // 記号はhyphenのみ許可
|
|
3
|
+
|
|
4
|
+
let projectId: string;
|
|
5
|
+
|
|
6
|
+
projectId = 'projectId';
|
|
7
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
8
|
+
|
|
9
|
+
projectId = 'projectid';
|
|
10
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
11
|
+
|
|
12
|
+
projectId = 'abcd1234-test';
|
|
13
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
14
|
+
|
|
15
|
+
projectId = 'a-z';
|
|
16
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
17
|
+
|
|
18
|
+
projectId = '0-9';
|
|
19
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
20
|
+
|
|
21
|
+
projectId = '---';
|
|
22
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
23
|
+
|
|
24
|
+
projectId = '-';
|
|
25
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
26
|
+
|
|
27
|
+
projectId = '&';
|
|
28
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
29
|
+
|
|
30
|
+
projectId = 'A';
|
|
31
|
+
console.log(projectId, ':', projectIdMustBe.test(projectId));
|
|
@@ -13,26 +13,36 @@ interface IExecuteSettings {
|
|
|
13
13
|
redisClient?: RedisClientType;
|
|
14
14
|
}
|
|
15
15
|
type IOperationExecute<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
16
|
-
type INextFunction = (task: Pick<factory.task.ITask<factory.taskName>, 'id'>) => IOperationExecute<void>;
|
|
16
|
+
type INextFunction = (task: Pick<factory.task.ITask<factory.taskName>, 'id' | 'remainingNumberOfTries' | 'name' | 'status' | 'data'>) => IOperationExecute<void>;
|
|
17
17
|
interface IReadyTask {
|
|
18
18
|
id: string;
|
|
19
19
|
name?: factory.taskName;
|
|
20
20
|
status: factory.taskStatus.Ready;
|
|
21
|
+
remainingNumberOfTries?: never;
|
|
21
22
|
expires?: Date;
|
|
22
23
|
executionResult?: never;
|
|
23
24
|
}
|
|
24
25
|
interface IRunningTask {
|
|
25
26
|
id: string;
|
|
26
27
|
status: factory.taskStatus.Running;
|
|
28
|
+
remainingNumberOfTries?: never;
|
|
27
29
|
name?: never;
|
|
28
30
|
expires?: never;
|
|
29
31
|
executionResult?: never;
|
|
30
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* 実行されたタスクイベント
|
|
35
|
+
*/
|
|
31
36
|
interface IExecutedTask {
|
|
32
37
|
id: string;
|
|
33
|
-
status: factory.taskStatus;
|
|
38
|
+
status: factory.taskStatus.Executed | factory.taskStatus.Running;
|
|
34
39
|
executionResult: factory.task.IExecutionResult;
|
|
35
|
-
|
|
40
|
+
/**
|
|
41
|
+
* 実行されたタスクの残り試行回数
|
|
42
|
+
*/
|
|
43
|
+
remainingNumberOfTries: number;
|
|
44
|
+
name: factory.taskName;
|
|
45
|
+
data: factory.task.IData<factory.taskName>;
|
|
36
46
|
expires?: never;
|
|
37
47
|
}
|
|
38
48
|
type IChangedTask = IReadyTask | IRunningTask | IExecutedTask;
|
|
@@ -77,8 +77,8 @@ export declare class SellerRepo {
|
|
|
77
77
|
}): Promise<void>;
|
|
78
78
|
getCursor(conditions: FilterQuery<factory.seller.ISeller>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
|
|
79
79
|
url?: string | undefined;
|
|
80
|
-
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
81
80
|
name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
|
|
81
|
+
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
82
82
|
typeOf: factory.organizationType.Corporation;
|
|
83
83
|
location?: factory.organization.ILocation | undefined;
|
|
84
84
|
additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
|
|
@@ -89,8 +89,8 @@ export declare class SellerRepo {
|
|
|
89
89
|
paymentAccepted?: factory.seller.IPaymentAccepted[] | undefined;
|
|
90
90
|
}> & {
|
|
91
91
|
url?: string | undefined;
|
|
92
|
-
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
93
92
|
name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
|
|
93
|
+
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
94
94
|
typeOf: factory.organizationType.Corporation;
|
|
95
95
|
location?: factory.organization.ILocation | undefined;
|
|
96
96
|
additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
|
|
@@ -103,8 +103,8 @@ export declare class SellerRepo {
|
|
|
103
103
|
_id: Types.ObjectId;
|
|
104
104
|
}, QueryOptions<import("mongoose").Document<unknown, {}, {
|
|
105
105
|
url?: string | undefined;
|
|
106
|
-
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
107
106
|
name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
|
|
107
|
+
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
108
108
|
typeOf: factory.organizationType.Corporation;
|
|
109
109
|
location?: factory.organization.ILocation | undefined;
|
|
110
110
|
additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
|
|
@@ -115,8 +115,8 @@ export declare class SellerRepo {
|
|
|
115
115
|
paymentAccepted?: factory.seller.IPaymentAccepted[] | undefined;
|
|
116
116
|
}> & {
|
|
117
117
|
url?: string | undefined;
|
|
118
|
-
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
119
118
|
name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
|
|
119
|
+
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
120
120
|
typeOf: factory.organizationType.Corporation;
|
|
121
121
|
location?: factory.organization.ILocation | undefined;
|
|
122
122
|
additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
|
|
@@ -23,7 +23,9 @@ interface IOptionOnCreate {
|
|
|
23
23
|
emitImmediately: boolean;
|
|
24
24
|
}
|
|
25
25
|
export type IExecutableTaskKeys = 'data' | 'id' | 'name' | 'status' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'expires';
|
|
26
|
-
export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys
|
|
26
|
+
export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys> & {
|
|
27
|
+
status: factory.taskStatus.Running;
|
|
28
|
+
};
|
|
27
29
|
type IKeyOfProjection = keyof factory.task.ITask<factory.taskName>;
|
|
28
30
|
type ICreatingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status' | 'identifier' | 'description'>;
|
|
29
31
|
/**
|
|
@@ -106,6 +108,9 @@ export declare class TaskRepo {
|
|
|
106
108
|
}): Promise<{
|
|
107
109
|
count: number;
|
|
108
110
|
}>;
|
|
111
|
+
/**
|
|
112
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
|
|
113
|
+
*/
|
|
109
114
|
emitRunningIfExists(params: {
|
|
110
115
|
name?: {
|
|
111
116
|
$eq?: factory.taskName;
|
|
@@ -121,16 +126,7 @@ export declare class TaskRepo {
|
|
|
121
126
|
numberOfTried?: factory.sortType;
|
|
122
127
|
runsAt: factory.sortType;
|
|
123
128
|
};
|
|
124
|
-
}): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
125
|
-
findExecutableOne(params: {
|
|
126
|
-
name?: {
|
|
127
|
-
$eq?: factory.taskName;
|
|
128
|
-
$nin?: factory.taskName[];
|
|
129
|
-
};
|
|
130
|
-
runsAt: {
|
|
131
|
-
$lt: Date;
|
|
132
|
-
};
|
|
133
|
-
}): Promise<IExecutableTask<factory.taskName> | null>;
|
|
129
|
+
}, next: INextFunction): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
134
130
|
/**
|
|
135
131
|
* emit OnTaskStatusChanged on delayed tasks
|
|
136
132
|
*/
|
|
@@ -168,11 +164,11 @@ export declare class TaskRepo {
|
|
|
168
164
|
* タスクID
|
|
169
165
|
*/
|
|
170
166
|
id: string;
|
|
171
|
-
status: factory.taskStatus;
|
|
167
|
+
status: factory.taskStatus.Executed | factory.taskStatus.Running;
|
|
168
|
+
remainingNumberOfTries: number;
|
|
169
|
+
name: factory.taskName;
|
|
170
|
+
data: factory.task.IData<factory.taskName>;
|
|
172
171
|
}, executionResult: factory.task.IExecutionResult, next?: INextFunction): Promise<void>;
|
|
173
|
-
/**
|
|
174
|
-
* 特定タスク検索
|
|
175
|
-
*/
|
|
176
172
|
count(params: factory.task.ISearchConditions): Promise<{
|
|
177
173
|
count: number;
|
|
178
174
|
}>;
|
|
@@ -213,69 +209,69 @@ export declare class TaskRepo {
|
|
|
213
209
|
count: number;
|
|
214
210
|
}>;
|
|
215
211
|
getCursor(conditions: FilterQuery<factory.task.ITask<factory.taskName>>, projection: ProjectionType<factory.task.ITask<factory.taskName>>): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
|
|
212
|
+
remainingNumberOfTries: number;
|
|
213
|
+
name: factory.taskName;
|
|
214
|
+
status: factory.taskStatus;
|
|
215
|
+
data: import("@chevre/factory/lib/task").IData;
|
|
216
216
|
alternateName?: string | undefined;
|
|
217
217
|
identifier?: string | undefined;
|
|
218
218
|
description?: string | undefined;
|
|
219
219
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
220
|
-
name: factory.taskName;
|
|
221
|
-
status: factory.taskStatus;
|
|
222
220
|
runsAt: Date;
|
|
223
|
-
remainingNumberOfTries: number;
|
|
224
221
|
lastTriedAt?: Date | undefined;
|
|
225
222
|
numberOfTried: number;
|
|
226
223
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
227
224
|
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
|
|
228
|
-
data: import("@chevre/factory/lib/task").IData;
|
|
229
225
|
dateAborted?: Date | undefined;
|
|
230
226
|
expires?: Date | undefined;
|
|
231
227
|
}> & {
|
|
228
|
+
remainingNumberOfTries: number;
|
|
229
|
+
name: factory.taskName;
|
|
230
|
+
status: factory.taskStatus;
|
|
231
|
+
data: import("@chevre/factory/lib/task").IData;
|
|
232
232
|
alternateName?: string | undefined;
|
|
233
233
|
identifier?: string | undefined;
|
|
234
234
|
description?: string | undefined;
|
|
235
235
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
236
|
-
name: factory.taskName;
|
|
237
|
-
status: factory.taskStatus;
|
|
238
236
|
runsAt: Date;
|
|
239
|
-
remainingNumberOfTries: number;
|
|
240
237
|
lastTriedAt?: Date | undefined;
|
|
241
238
|
numberOfTried: number;
|
|
242
239
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
243
240
|
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
|
|
244
|
-
data: import("@chevre/factory/lib/task").IData;
|
|
245
241
|
dateAborted?: Date | undefined;
|
|
246
242
|
expires?: Date | undefined;
|
|
247
243
|
} & {
|
|
248
244
|
_id: import("mongoose").Types.ObjectId;
|
|
249
245
|
}, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, {
|
|
246
|
+
remainingNumberOfTries: number;
|
|
247
|
+
name: factory.taskName;
|
|
248
|
+
status: factory.taskStatus;
|
|
249
|
+
data: import("@chevre/factory/lib/task").IData;
|
|
250
250
|
alternateName?: string | undefined;
|
|
251
251
|
identifier?: string | undefined;
|
|
252
252
|
description?: string | undefined;
|
|
253
253
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
254
|
-
name: factory.taskName;
|
|
255
|
-
status: factory.taskStatus;
|
|
256
254
|
runsAt: Date;
|
|
257
|
-
remainingNumberOfTries: number;
|
|
258
255
|
lastTriedAt?: Date | undefined;
|
|
259
256
|
numberOfTried: number;
|
|
260
257
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
261
258
|
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
|
|
262
|
-
data: import("@chevre/factory/lib/task").IData;
|
|
263
259
|
dateAborted?: Date | undefined;
|
|
264
260
|
expires?: Date | undefined;
|
|
265
261
|
}> & {
|
|
262
|
+
remainingNumberOfTries: number;
|
|
263
|
+
name: factory.taskName;
|
|
264
|
+
status: factory.taskStatus;
|
|
265
|
+
data: import("@chevre/factory/lib/task").IData;
|
|
266
266
|
alternateName?: string | undefined;
|
|
267
267
|
identifier?: string | undefined;
|
|
268
268
|
description?: string | undefined;
|
|
269
269
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
270
|
-
name: factory.taskName;
|
|
271
|
-
status: factory.taskStatus;
|
|
272
270
|
runsAt: Date;
|
|
273
|
-
remainingNumberOfTries: number;
|
|
274
271
|
lastTriedAt?: Date | undefined;
|
|
275
272
|
numberOfTried: number;
|
|
276
273
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
277
274
|
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
|
|
278
|
-
data: import("@chevre/factory/lib/task").IData;
|
|
279
275
|
dateAborted?: Date | undefined;
|
|
280
276
|
expires?: Date | undefined;
|
|
281
277
|
} & {
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -242,48 +242,6 @@ class TaskRepo {
|
|
|
242
242
|
return { id, status };
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
|
-
// public async createIfNotExistByIdentifier(
|
|
246
|
-
// params: factory.task.IAttributes<factory.taskName> & {
|
|
247
|
-
// // resolve uniqueness of identifier(2025-03-27~)
|
|
248
|
-
// identifier: string;
|
|
249
|
-
// },
|
|
250
|
-
// options: IOptionOnCreate
|
|
251
|
-
// ): Promise<void> {
|
|
252
|
-
// if (typeof params.identifier !== 'string' || params.identifier.length === 0) {
|
|
253
|
-
// throw new factory.errors.ArgumentNull('identifier');
|
|
254
|
-
// }
|
|
255
|
-
// try {
|
|
256
|
-
// const createdTask = await this.taskModel.findOneAndUpdate(
|
|
257
|
-
// {
|
|
258
|
-
// 'project.id': { $eq: params.project.id },
|
|
259
|
-
// name: { $eq: params.name },
|
|
260
|
-
// identifier: { $exists: true, $eq: params.identifier }
|
|
261
|
-
// },
|
|
262
|
-
// { $setOnInsert: params },
|
|
263
|
-
// { new: true, upsert: true }
|
|
264
|
-
// )
|
|
265
|
-
// .select({ _id: 1 })
|
|
266
|
-
// .exec();
|
|
267
|
-
// if (options.emitImmediately) {
|
|
268
|
-
// taskEventEmitter.emitTaskStatusChanged({
|
|
269
|
-
// id: createdTask.id,
|
|
270
|
-
// name: params.name,
|
|
271
|
-
// status: factory.taskStatus.Ready
|
|
272
|
-
// });
|
|
273
|
-
// }
|
|
274
|
-
// } catch (error) {
|
|
275
|
-
// let throwsError = true;
|
|
276
|
-
// if (await isMongoError(error)) {
|
|
277
|
-
// // すでにidentifierが存在する場合ok
|
|
278
|
-
// if (error.code === MongoErrorCode.DuplicateKey) {
|
|
279
|
-
// throwsError = false;
|
|
280
|
-
// }
|
|
281
|
-
// }
|
|
282
|
-
// if (throwsError) {
|
|
283
|
-
// throw error;
|
|
284
|
-
// }
|
|
285
|
-
// }
|
|
286
|
-
// }
|
|
287
245
|
/**
|
|
288
246
|
* タスク識別子から冪等作成する
|
|
289
247
|
* reimplement createIfNotExistByIdentifier(2025-03-28~)
|
|
@@ -341,40 +299,6 @@ class TaskRepo {
|
|
|
341
299
|
}
|
|
342
300
|
});
|
|
343
301
|
}
|
|
344
|
-
// public async createInformTaskIfNotExist(
|
|
345
|
-
// // resolve uniqueness of identifier(2025-03-27~)
|
|
346
|
-
// params: Pick<
|
|
347
|
-
// factory.task.IAttributes<factory.taskName.TriggerWebhook>,
|
|
348
|
-
// 'data' | 'executionResults' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'
|
|
349
|
-
// > & {
|
|
350
|
-
// data: factory.task.triggerWebhook.IInformAnyResourceAction & {
|
|
351
|
-
// object: factory.notification.person.IPersonAsNotification;
|
|
352
|
-
// };
|
|
353
|
-
// },
|
|
354
|
-
// options: IOptionOnCreate
|
|
355
|
-
// ): Promise<void> {
|
|
356
|
-
// const createdTask = await this.taskModel.findOneAndUpdate(
|
|
357
|
-
// {
|
|
358
|
-
// 'project.id': { $eq: params.project.id },
|
|
359
|
-
// name: params.name,
|
|
360
|
-
// 'data.object.id': {
|
|
361
|
-
// $exists: true,
|
|
362
|
-
// $eq: String(params.data.object.id)
|
|
363
|
-
// }
|
|
364
|
-
// },
|
|
365
|
-
// { $setOnInsert: params },
|
|
366
|
-
// { new: true, upsert: true }
|
|
367
|
-
// )
|
|
368
|
-
// .select({ _id: 1 })
|
|
369
|
-
// .exec();
|
|
370
|
-
// if (options.emitImmediately) {
|
|
371
|
-
// taskEventEmitter.emitTaskStatusChanged({
|
|
372
|
-
// id: createdTask.id,
|
|
373
|
-
// name: params.name,
|
|
374
|
-
// status: factory.taskStatus.Ready
|
|
375
|
-
// });
|
|
376
|
-
// }
|
|
377
|
-
// }
|
|
378
302
|
/**
|
|
379
303
|
* 取引削除タスク冪等作成
|
|
380
304
|
*/
|
|
@@ -552,7 +476,11 @@ class TaskRepo {
|
|
|
552
476
|
return { count };
|
|
553
477
|
});
|
|
554
478
|
}
|
|
555
|
-
|
|
479
|
+
/**
|
|
480
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
|
|
481
|
+
*/
|
|
482
|
+
emitRunningIfExists(params, next // support next function(2025-08-02~)
|
|
483
|
+
) {
|
|
556
484
|
return __awaiter(this, void 0, void 0, function* () {
|
|
557
485
|
var _a, _b;
|
|
558
486
|
if (!(params.runsAt.$lt instanceof Date)) {
|
|
@@ -591,40 +519,55 @@ class TaskRepo {
|
|
|
591
519
|
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
592
520
|
id: doc.id,
|
|
593
521
|
status: factory.taskStatus.Running
|
|
594
|
-
});
|
|
595
|
-
return doc;
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
findExecutableOne(params) {
|
|
599
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
600
|
-
var _a, _b;
|
|
601
|
-
if (!(params.runsAt.$lt instanceof Date)) {
|
|
602
|
-
throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
603
|
-
}
|
|
604
|
-
const nameEq = (_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq;
|
|
605
|
-
const nameNin = (_b = params.name) === null || _b === void 0 ? void 0 : _b.$nin;
|
|
606
|
-
const query = this.taskModel.findOne(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: params.runsAt.$lt } }, (typeof nameEq === 'string' || Array.isArray(nameNin))
|
|
607
|
-
? {
|
|
608
|
-
name: Object.assign(Object.assign({}, (typeof nameEq === 'string') ? { $eq: nameEq } : undefined), (Array.isArray(nameNin)) ? { $nin: nameNin } : undefined)
|
|
609
|
-
}
|
|
610
|
-
: undefined), executableTaskProjection)
|
|
611
|
-
.sort({
|
|
612
|
-
runsAt: factory.sortType.Ascending
|
|
613
|
-
});
|
|
614
|
-
// .hint('executeOneByName');
|
|
615
|
-
// const explainResult = await query.explain();
|
|
616
|
-
// console.dir(explainResult, { depth: null });
|
|
617
|
-
// console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
|
|
618
|
-
const doc = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
619
|
-
.lean()
|
|
620
|
-
.exec();
|
|
621
|
-
if (doc === null) {
|
|
622
|
-
// tslint:disable-next-line:no-null-keyword
|
|
623
|
-
return null;
|
|
624
|
-
}
|
|
522
|
+
}, next);
|
|
625
523
|
return doc;
|
|
626
524
|
});
|
|
627
525
|
}
|
|
526
|
+
// public async findExecutableOne(params: {
|
|
527
|
+
// name?: {
|
|
528
|
+
// $eq?: factory.taskName;
|
|
529
|
+
// $nin?: factory.taskName[];
|
|
530
|
+
// };
|
|
531
|
+
// runsAt: {
|
|
532
|
+
// $lt: Date;
|
|
533
|
+
// };
|
|
534
|
+
// }): Promise<IExecutableTask<factory.taskName> | null> {
|
|
535
|
+
// if (!(params.runsAt.$lt instanceof Date)) {
|
|
536
|
+
// throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
537
|
+
// }
|
|
538
|
+
// const nameEq = params.name?.$eq;
|
|
539
|
+
// const nameNin = params.name?.$nin;
|
|
540
|
+
// const query = this.taskModel.findOne(
|
|
541
|
+
// {
|
|
542
|
+
// status: { $eq: factory.taskStatus.Ready },
|
|
543
|
+
// runsAt: { $lt: params.runsAt.$lt },
|
|
544
|
+
// ...(typeof nameEq === 'string' || Array.isArray(nameNin))
|
|
545
|
+
// ? {
|
|
546
|
+
// name: {
|
|
547
|
+
// ...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined,
|
|
548
|
+
// ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
|
|
549
|
+
// }
|
|
550
|
+
// }
|
|
551
|
+
// : undefined
|
|
552
|
+
// },
|
|
553
|
+
// executableTaskProjection
|
|
554
|
+
// )
|
|
555
|
+
// .sort({
|
|
556
|
+
// runsAt: factory.sortType.Ascending
|
|
557
|
+
// });
|
|
558
|
+
// // .hint('executeOneByName');
|
|
559
|
+
// // const explainResult = await query.explain();
|
|
560
|
+
// // console.dir(explainResult, { depth: null });
|
|
561
|
+
// // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
|
|
562
|
+
// const doc = await query.setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
563
|
+
// .lean<IExecutableTask<factory.taskName>>()
|
|
564
|
+
// .exec();
|
|
565
|
+
// if (doc === null) {
|
|
566
|
+
// // tslint:disable-next-line:no-null-keyword
|
|
567
|
+
// return null;
|
|
568
|
+
// }
|
|
569
|
+
// return doc;
|
|
570
|
+
// }
|
|
628
571
|
// discontinue(2025-05-26~)
|
|
629
572
|
/**
|
|
630
573
|
* emit OnTaskStatusChanged on delayed tasks
|
|
@@ -800,7 +743,7 @@ class TaskRepo {
|
|
|
800
743
|
// support customr function(2025-05-25~)
|
|
801
744
|
next) {
|
|
802
745
|
return __awaiter(this, void 0, void 0, function* () {
|
|
803
|
-
const { id, status } = params;
|
|
746
|
+
const { id, status, remainingNumberOfTries, name, data } = params;
|
|
804
747
|
yield this.taskModel.updateOne({ _id: { $eq: id } }, {
|
|
805
748
|
$set: { status },
|
|
806
749
|
$push: { executionResults: executionResult }
|
|
@@ -808,34 +751,11 @@ class TaskRepo {
|
|
|
808
751
|
.exec();
|
|
809
752
|
// emit event(2025-05-26~)
|
|
810
753
|
if (typeof next === 'function') {
|
|
811
|
-
|
|
754
|
+
const changedTask = { id, name, status, data, remainingNumberOfTries, executionResult };
|
|
755
|
+
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
|
|
812
756
|
}
|
|
813
757
|
});
|
|
814
758
|
}
|
|
815
|
-
/**
|
|
816
|
-
* 特定タスク検索
|
|
817
|
-
*/
|
|
818
|
-
// public async findById<T extends factory.taskName>(params: {
|
|
819
|
-
// name: T;
|
|
820
|
-
// id: string;
|
|
821
|
-
// }): Promise<factory.task.ITask<T>> {
|
|
822
|
-
// const doc = await this.taskModel.findOne(
|
|
823
|
-
// {
|
|
824
|
-
// name: { $eq: params.name },
|
|
825
|
-
// _id: { $eq: params.id }
|
|
826
|
-
// },
|
|
827
|
-
// {
|
|
828
|
-
// __v: 0,
|
|
829
|
-
// createdAt: 0,
|
|
830
|
-
// updatedAt: 0
|
|
831
|
-
// }
|
|
832
|
-
// )
|
|
833
|
-
// .exec();
|
|
834
|
-
// if (doc === null) {
|
|
835
|
-
// throw new factory.errors.NotFound('Task');
|
|
836
|
-
// }
|
|
837
|
-
// return doc.toObject();
|
|
838
|
-
// }
|
|
839
759
|
count(params) {
|
|
840
760
|
return __awaiter(this, void 0, void 0, function* () {
|
|
841
761
|
const { limit } = params;
|
|
@@ -18,7 +18,7 @@ export declare function validateStartParams(params: IStartParams): (repos: {
|
|
|
18
18
|
assetTransaction: AssetTransactionRepo;
|
|
19
19
|
}) => Promise<{
|
|
20
20
|
reserveTransaction: import("@chevre/factory/lib/assetTransaction/reserve").ITransaction | undefined;
|
|
21
|
-
reservations: (Pick<import("@chevre/factory/lib/reservation/event").IReservation, "id" | "typeOf" | "
|
|
21
|
+
reservations: (Pick<import("@chevre/factory/lib/reservation/event").IReservation, "id" | "typeOf" | "issuedThrough" | "reservationNumber"> & {
|
|
22
22
|
reservationFor: Pick<factory.reservation.IReservationFor<factory.reservationType.EventReservation>, "id" | "typeOf">;
|
|
23
23
|
})[] | undefined;
|
|
24
24
|
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SendGridCredentials } from '../../credentials/sendGrid';
|
|
2
|
+
import type { TaskRepo } from '../../repo/task';
|
|
3
|
+
import { Settings } from '../../settings';
|
|
4
|
+
/**
|
|
5
|
+
* 中止されたタスクリストをEメールで通知する
|
|
6
|
+
* add(2025-03-13~)
|
|
7
|
+
*/
|
|
8
|
+
declare function notifyAbortedTasksByEmail(params: {
|
|
9
|
+
dateAbortedGte: Date;
|
|
10
|
+
}): (repos: {
|
|
11
|
+
task: TaskRepo;
|
|
12
|
+
}, settings: Pick<Settings, "abortedTasksWithoutReport">, credentials: {
|
|
13
|
+
sendGrid: SendGridCredentials;
|
|
14
|
+
}) => Promise<void>;
|
|
15
|
+
export { notifyAbortedTasksByEmail };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.notifyAbortedTasksByEmail = notifyAbortedTasksByEmail;
|
|
13
|
+
const createDebug = require("debug");
|
|
14
|
+
const factory = require("../../factory");
|
|
15
|
+
const factory_1 = require("./factory");
|
|
16
|
+
const notifyByEmail_1 = require("./notifyByEmail");
|
|
17
|
+
const debug = createDebug('chevre-domain:service:notification');
|
|
18
|
+
/**
|
|
19
|
+
* 中止されたタスクリストをEメールで通知する
|
|
20
|
+
* add(2025-03-13~)
|
|
21
|
+
*/
|
|
22
|
+
function notifyAbortedTasksByEmail(params) {
|
|
23
|
+
return (repos, settings, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const { abortedTasksWithoutReport } = settings;
|
|
25
|
+
const abortedTasks = yield repos.task.projectFields(Object.assign({ status: { $eq: factory.taskStatus.Aborted }, dateAborted: { $gte: params.dateAbortedGte } }, (abortedTasksWithoutReport.length > 0)
|
|
26
|
+
? { name: { $nin: abortedTasksWithoutReport } }
|
|
27
|
+
: undefined), []);
|
|
28
|
+
if (abortedTasks.length > 0) {
|
|
29
|
+
// 開発者へ報告
|
|
30
|
+
const message = (0, factory_1.tasks2lineNotify)({ tasks: abortedTasks });
|
|
31
|
+
const notifyResult = yield (0, notifyByEmail_1.notifyByEmail)({
|
|
32
|
+
subject: message.subject, content: message.content,
|
|
33
|
+
logLevel: 'error'
|
|
34
|
+
})({}, credentials);
|
|
35
|
+
debug('notifyResult:', notifyResult);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { notifyAbortedTasksByEmail } from './notification/notifyAbortedTasksByEmail';
|
|
1
2
|
import { notifyByEmail } from './notification/notifyByEmail';
|
|
2
3
|
import { sendEmailMessage } from './notification/sendEmailMessage';
|
|
3
4
|
import { triggerWebhook } from './notification/triggerWebhook';
|
|
4
|
-
export { notifyByEmail, sendEmailMessage, triggerWebhook };
|
|
5
|
+
export { notifyAbortedTasksByEmail, notifyByEmail, sendEmailMessage, triggerWebhook };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.triggerWebhook = exports.sendEmailMessage = exports.notifyByEmail = void 0;
|
|
3
|
+
exports.triggerWebhook = exports.sendEmailMessage = exports.notifyByEmail = exports.notifyAbortedTasksByEmail = void 0;
|
|
4
|
+
const notifyAbortedTasksByEmail_1 = require("./notification/notifyAbortedTasksByEmail");
|
|
5
|
+
Object.defineProperty(exports, "notifyAbortedTasksByEmail", { enumerable: true, get: function () { return notifyAbortedTasksByEmail_1.notifyAbortedTasksByEmail; } });
|
|
4
6
|
const notifyByEmail_1 = require("./notification/notifyByEmail");
|
|
5
7
|
Object.defineProperty(exports, "notifyByEmail", { enumerable: true, get: function () { return notifyByEmail_1.notifyByEmail; } });
|
|
6
8
|
const sendEmailMessage_1 = require("./notification/sendEmailMessage");
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import * as factory from '../../factory';
|
|
2
|
-
import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../
|
|
3
|
-
export declare function call(params: Pick<factory.task.aggregateOnSystem.ITask, IExecutableTaskKeys>
|
|
2
|
+
import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../taskHandler';
|
|
3
|
+
export declare function call(params: Pick<factory.task.aggregateOnSystem.ITask, IExecutableTaskKeys> & {
|
|
4
|
+
status: factory.taskStatus.Running;
|
|
5
|
+
}): IOperationExecute<ICallResult>;
|