@chevre/domain 22.11.0-alpha.12 → 22.11.0-alpha.13
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/regex.ts +31 -0
- package/lib/chevre/eventEmitter/task.d.ts +10 -1
- package/lib/chevre/repo/task.d.ts +9 -5
- package/lib/chevre/repo/task.js +9 -4
- 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 +1 -1
- 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 +1 -1
- 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 +98 -0
- package/lib/chevre/settings/aggregation.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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,25 +13,34 @@ 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'>) => 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
38
|
status: factory.taskStatus;
|
|
34
39
|
executionResult: factory.task.IExecutionResult;
|
|
40
|
+
/**
|
|
41
|
+
* 実行されたタスクの残り試行回数
|
|
42
|
+
*/
|
|
43
|
+
remainingNumberOfTries: number;
|
|
35
44
|
name?: never;
|
|
36
45
|
expires?: never;
|
|
37
46
|
}
|
|
@@ -106,6 +106,9 @@ export declare class TaskRepo {
|
|
|
106
106
|
}): Promise<{
|
|
107
107
|
count: number;
|
|
108
108
|
}>;
|
|
109
|
+
/**
|
|
110
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
|
|
111
|
+
*/
|
|
109
112
|
emitRunningIfExists(params: {
|
|
110
113
|
name?: {
|
|
111
114
|
$eq?: factory.taskName;
|
|
@@ -121,7 +124,7 @@ export declare class TaskRepo {
|
|
|
121
124
|
numberOfTried?: factory.sortType;
|
|
122
125
|
runsAt: factory.sortType;
|
|
123
126
|
};
|
|
124
|
-
}): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
127
|
+
}, next: INextFunction): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
125
128
|
findExecutableOne(params: {
|
|
126
129
|
name?: {
|
|
127
130
|
$eq?: factory.taskName;
|
|
@@ -169,6 +172,7 @@ export declare class TaskRepo {
|
|
|
169
172
|
*/
|
|
170
173
|
id: string;
|
|
171
174
|
status: factory.taskStatus;
|
|
175
|
+
remainingNumberOfTries: number;
|
|
172
176
|
}, executionResult: factory.task.IExecutionResult, next?: INextFunction): Promise<void>;
|
|
173
177
|
/**
|
|
174
178
|
* 特定タスク検索
|
|
@@ -213,6 +217,7 @@ export declare class TaskRepo {
|
|
|
213
217
|
count: number;
|
|
214
218
|
}>;
|
|
215
219
|
getCursor(conditions: FilterQuery<factory.task.ITask<factory.taskName>>, projection: ProjectionType<factory.task.ITask<factory.taskName>>): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
|
|
220
|
+
remainingNumberOfTries: number;
|
|
216
221
|
alternateName?: string | undefined;
|
|
217
222
|
identifier?: string | undefined;
|
|
218
223
|
description?: string | undefined;
|
|
@@ -220,7 +225,6 @@ export declare class TaskRepo {
|
|
|
220
225
|
name: factory.taskName;
|
|
221
226
|
status: factory.taskStatus;
|
|
222
227
|
runsAt: Date;
|
|
223
|
-
remainingNumberOfTries: number;
|
|
224
228
|
lastTriedAt?: Date | undefined;
|
|
225
229
|
numberOfTried: number;
|
|
226
230
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
@@ -229,6 +233,7 @@ export declare class TaskRepo {
|
|
|
229
233
|
dateAborted?: Date | undefined;
|
|
230
234
|
expires?: Date | undefined;
|
|
231
235
|
}> & {
|
|
236
|
+
remainingNumberOfTries: number;
|
|
232
237
|
alternateName?: string | undefined;
|
|
233
238
|
identifier?: string | undefined;
|
|
234
239
|
description?: string | undefined;
|
|
@@ -236,7 +241,6 @@ export declare class TaskRepo {
|
|
|
236
241
|
name: factory.taskName;
|
|
237
242
|
status: factory.taskStatus;
|
|
238
243
|
runsAt: Date;
|
|
239
|
-
remainingNumberOfTries: number;
|
|
240
244
|
lastTriedAt?: Date | undefined;
|
|
241
245
|
numberOfTried: number;
|
|
242
246
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
@@ -247,6 +251,7 @@ export declare class TaskRepo {
|
|
|
247
251
|
} & {
|
|
248
252
|
_id: import("mongoose").Types.ObjectId;
|
|
249
253
|
}, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, {
|
|
254
|
+
remainingNumberOfTries: number;
|
|
250
255
|
alternateName?: string | undefined;
|
|
251
256
|
identifier?: string | undefined;
|
|
252
257
|
description?: string | undefined;
|
|
@@ -254,7 +259,6 @@ export declare class TaskRepo {
|
|
|
254
259
|
name: factory.taskName;
|
|
255
260
|
status: factory.taskStatus;
|
|
256
261
|
runsAt: Date;
|
|
257
|
-
remainingNumberOfTries: number;
|
|
258
262
|
lastTriedAt?: Date | undefined;
|
|
259
263
|
numberOfTried: number;
|
|
260
264
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
@@ -263,6 +267,7 @@ export declare class TaskRepo {
|
|
|
263
267
|
dateAborted?: Date | undefined;
|
|
264
268
|
expires?: Date | undefined;
|
|
265
269
|
}> & {
|
|
270
|
+
remainingNumberOfTries: number;
|
|
266
271
|
alternateName?: string | undefined;
|
|
267
272
|
identifier?: string | undefined;
|
|
268
273
|
description?: string | undefined;
|
|
@@ -270,7 +275,6 @@ export declare class TaskRepo {
|
|
|
270
275
|
name: factory.taskName;
|
|
271
276
|
status: factory.taskStatus;
|
|
272
277
|
runsAt: Date;
|
|
273
|
-
remainingNumberOfTries: number;
|
|
274
278
|
lastTriedAt?: Date | undefined;
|
|
275
279
|
numberOfTried: number;
|
|
276
280
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -552,7 +552,11 @@ class TaskRepo {
|
|
|
552
552
|
return { count };
|
|
553
553
|
});
|
|
554
554
|
}
|
|
555
|
-
|
|
555
|
+
/**
|
|
556
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningスタータスに変更した上で、Runningイベントを発生させる
|
|
557
|
+
*/
|
|
558
|
+
emitRunningIfExists(params, next // support next function(2025-08-02~)
|
|
559
|
+
) {
|
|
556
560
|
return __awaiter(this, void 0, void 0, function* () {
|
|
557
561
|
var _a, _b;
|
|
558
562
|
if (!(params.runsAt.$lt instanceof Date)) {
|
|
@@ -591,7 +595,7 @@ class TaskRepo {
|
|
|
591
595
|
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
592
596
|
id: doc.id,
|
|
593
597
|
status: factory.taskStatus.Running
|
|
594
|
-
});
|
|
598
|
+
}, next);
|
|
595
599
|
return doc;
|
|
596
600
|
});
|
|
597
601
|
}
|
|
@@ -800,7 +804,7 @@ class TaskRepo {
|
|
|
800
804
|
// support customr function(2025-05-25~)
|
|
801
805
|
next) {
|
|
802
806
|
return __awaiter(this, void 0, void 0, function* () {
|
|
803
|
-
const { id, status } = params;
|
|
807
|
+
const { id, status, remainingNumberOfTries } = params;
|
|
804
808
|
yield this.taskModel.updateOne({ _id: { $eq: id } }, {
|
|
805
809
|
$set: { status },
|
|
806
810
|
$push: { executionResults: executionResult }
|
|
@@ -808,7 +812,8 @@ class TaskRepo {
|
|
|
808
812
|
.exec();
|
|
809
813
|
// emit event(2025-05-26~)
|
|
810
814
|
if (typeof next === 'function') {
|
|
811
|
-
|
|
815
|
+
const changedTask = { id, status, remainingNumberOfTries, executionResult };
|
|
816
|
+
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask, next);
|
|
812
817
|
}
|
|
813
818
|
});
|
|
814
819
|
}
|
|
@@ -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,3 @@
|
|
|
1
1
|
import * as factory from '../../factory';
|
|
2
|
-
import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../
|
|
2
|
+
import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../taskHandler';
|
|
3
3
|
export declare function call(params: Pick<factory.task.aggregateOnSystem.ITask, IExecutableTaskKeys>): IOperationExecute<ICallResult>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IOperationExecute } from '../
|
|
1
|
+
import type { IOperationExecute } from '../taskHandler';
|
|
2
2
|
import * as factory from '../../factory';
|
|
3
3
|
import { ActionRepo } from '../../repo/action';
|
|
4
4
|
import { AssetTransactionRepo } from '../../repo/assetTransaction';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as COA from '@motionpicture/coa-service';
|
|
2
2
|
import * as factory from '../../factory';
|
|
3
3
|
import { Settings } from '../../settings';
|
|
4
|
-
import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../
|
|
4
|
+
import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../taskHandler';
|
|
5
5
|
import { AcceptedOfferRepo } from '../../repo/acceptedOffer';
|
|
6
6
|
import { ActionRepo } from '../../repo/action';
|
|
7
7
|
import { AssetTransactionRepo } from '../../repo/assetTransaction';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as factory from '../../factory';
|
|
2
|
-
import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../
|
|
2
|
+
import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../taskHandler';
|
|
3
3
|
export declare function call(params: Pick<factory.task.handleNotification.ITask, IExecutableTaskKeys>): IOperationExecute<ICallResult>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { IExecutableTaskKeys, IOperationExecute } from '../
|
|
1
|
+
import type { IExecutableTaskKeys, IOperationExecute } from '../taskHandler';
|
|
2
2
|
import * as factory from '../../factory';
|
|
3
3
|
export declare function call(params: Pick<factory.task.invalidatePaymentUrl.ITask, IExecutableTaskKeys>): IOperationExecute<void>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SendGridCredentials } from '../credentials/sendGrid';
|
|
2
2
|
import type { IExecuteSettings as IMinimumExecuteSettings, INextFunction, IReadyTask, IRunningTask } from '../eventEmitter/task';
|
|
3
3
|
import * as factory from '../factory';
|
|
4
|
-
import type { IExecutableTask, IExecutableTaskKeys, TaskRepo } from '../repo/task';
|
|
5
4
|
import { Settings } from '../settings';
|
|
6
5
|
import { AggregationSettings } from '../settings/aggregation';
|
|
7
6
|
interface ICredentialSettings {
|
|
@@ -12,14 +11,7 @@ interface IExecuteSettings extends IMinimumExecuteSettings {
|
|
|
12
11
|
settings: Settings;
|
|
13
12
|
aggregationSettings?: AggregationSettings;
|
|
14
13
|
}
|
|
15
|
-
interface IExecuteOptions {
|
|
16
|
-
executeById: boolean;
|
|
17
|
-
executeByName: boolean;
|
|
18
|
-
}
|
|
19
14
|
type IOperation<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
20
|
-
type IOperationExecute<T> = (settings: IExecuteSettings, options: IExecuteOptions) => Promise<T>;
|
|
21
|
-
type ICallResult = void | Pick<factory.task.IExecutionResult, 'error'>;
|
|
22
|
-
export type ICallableTaskOperation = (task: IExecutableTask<factory.taskName>) => IOperationExecute<ICallResult>;
|
|
23
15
|
/**
|
|
24
16
|
* タスク変更イベントを受けて実行する
|
|
25
17
|
*/
|
|
@@ -49,18 +41,4 @@ declare function executeOneIfExists(params: {
|
|
|
49
41
|
$lt: Date;
|
|
50
42
|
};
|
|
51
43
|
}): IOperation<void>;
|
|
52
|
-
|
|
53
|
-
* タスクを実行する
|
|
54
|
-
*/
|
|
55
|
-
declare function execute(task: IExecutableTask<factory.taskName>, next?: INextFunction): IOperationExecute<void>;
|
|
56
|
-
/**
|
|
57
|
-
* add(2025-03-13~)
|
|
58
|
-
*/
|
|
59
|
-
declare function notifyAbortedTasksByEmail(params: {
|
|
60
|
-
dateAbortedGte: Date;
|
|
61
|
-
}): (repos: {
|
|
62
|
-
task: TaskRepo;
|
|
63
|
-
}, settings: Pick<Settings, "abortedTasksWithoutReport">, credentials: {
|
|
64
|
-
sendGrid: SendGridCredentials;
|
|
65
|
-
}) => Promise<void>;
|
|
66
|
-
export { ICallResult, IExecutableTaskKeys, IOperationExecute, executeById, executeOneIfExists, execute, notifyAbortedTasksByEmail };
|
|
44
|
+
export { executeById, executeOneIfExists };
|
|
@@ -11,15 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.executeById = executeById;
|
|
13
13
|
exports.executeOneIfExists = executeOneIfExists;
|
|
14
|
-
exports.execute = execute;
|
|
15
|
-
exports.notifyAbortedTasksByEmail = notifyAbortedTasksByEmail;
|
|
16
14
|
/**
|
|
17
15
|
* タスクサービス
|
|
18
16
|
*/
|
|
19
17
|
const createDebug = require("debug");
|
|
20
|
-
const
|
|
21
|
-
const factory = require("../factory");
|
|
22
|
-
const factory_1 = require("./notification/factory");
|
|
18
|
+
const taskHandler_1 = require("./taskHandler");
|
|
23
19
|
const debug = createDebug('chevre-domain:service:task');
|
|
24
20
|
/**
|
|
25
21
|
* タスク変更イベントを受けて実行する
|
|
@@ -42,7 +38,7 @@ function executeById(params, next) {
|
|
|
42
38
|
}
|
|
43
39
|
// タスクがなければ終了
|
|
44
40
|
if (task !== null) {
|
|
45
|
-
yield
|
|
41
|
+
yield (0, taskHandler_1.executeTask)(task, (typeof next === 'function') ? next : undefined)(settings, {
|
|
46
42
|
executeById: true,
|
|
47
43
|
executeByName: false
|
|
48
44
|
});
|
|
@@ -70,113 +66,10 @@ function executeOneIfExists(params) {
|
|
|
70
66
|
}
|
|
71
67
|
// タスクがなければ終了
|
|
72
68
|
if (task !== null) {
|
|
73
|
-
yield
|
|
69
|
+
yield (0, taskHandler_1.executeTask)(task)(settings, {
|
|
74
70
|
executeById: false,
|
|
75
71
|
executeByName: (typeof ((_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq) === 'string')
|
|
76
72
|
});
|
|
77
73
|
}
|
|
78
74
|
});
|
|
79
75
|
}
|
|
80
|
-
/**
|
|
81
|
-
* タスクを実行する
|
|
82
|
-
*/
|
|
83
|
-
function execute(task, next) {
|
|
84
|
-
const now = new Date();
|
|
85
|
-
debug('executing an executableTask...', task, now);
|
|
86
|
-
return (settings, options) => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
const taskRepo = new (yield Promise.resolve().then(() => require('../repo/task'))).TaskRepo(settings.connection);
|
|
88
|
-
try {
|
|
89
|
-
// 期限検証(2024-04-23~)
|
|
90
|
-
if (task.expires instanceof Date) {
|
|
91
|
-
const taskExpired = moment(now)
|
|
92
|
-
.isAfter(task.expires);
|
|
93
|
-
if (taskExpired) {
|
|
94
|
-
throw new factory.errors.Internal(`task expired [expires:${task.expires}]`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// タスク名の関数が定義されていなければ、TypeErrorとなる
|
|
98
|
-
let callResult;
|
|
99
|
-
const { call } = yield Promise.resolve(`${`./task/${task.name}`}`).then(s => require(s));
|
|
100
|
-
switch (task.name) {
|
|
101
|
-
case factory.taskName.AcceptCOAOffer:
|
|
102
|
-
case factory.taskName.AggregateOnSystem:
|
|
103
|
-
case factory.taskName.AuthorizePayment:
|
|
104
|
-
case factory.taskName.CancelPendingReservation:
|
|
105
|
-
case factory.taskName.CheckMovieTicket:
|
|
106
|
-
case factory.taskName.DeletePerson:
|
|
107
|
-
case factory.taskName.HandleNotification:
|
|
108
|
-
case factory.taskName.ImportEventCapacitiesFromCOA:
|
|
109
|
-
case factory.taskName.ImportEventsFromCOA:
|
|
110
|
-
case factory.taskName.ImportOffersFromCOA:
|
|
111
|
-
case factory.taskName.InvalidatePaymentUrl:
|
|
112
|
-
case factory.taskName.OnAuthorizationCreated:
|
|
113
|
-
case factory.taskName.Pay:
|
|
114
|
-
case factory.taskName.PublishPaymentUrl:
|
|
115
|
-
case factory.taskName.Refund:
|
|
116
|
-
case factory.taskName.VoidPayTransaction:
|
|
117
|
-
case factory.taskName.VoidReserveTransaction:
|
|
118
|
-
case factory.taskName.ConfirmReserveTransaction:
|
|
119
|
-
case factory.taskName.ReturnPayTransaction:
|
|
120
|
-
case factory.taskName.ReturnReserveTransaction:
|
|
121
|
-
case factory.taskName.SendEmailMessage:
|
|
122
|
-
case factory.taskName.TriggerWebhook:
|
|
123
|
-
callResult = yield call(task)(settings, options);
|
|
124
|
-
break;
|
|
125
|
-
default:
|
|
126
|
-
yield call(task.data)(settings);
|
|
127
|
-
}
|
|
128
|
-
const result = {
|
|
129
|
-
executedAt: now,
|
|
130
|
-
endDate: new Date(),
|
|
131
|
-
// enable overwriting task.executionResults.error on Executed(2024-05-29~)
|
|
132
|
-
error: ((callResult === null || callResult === void 0 ? void 0 : callResult.error) instanceof Error)
|
|
133
|
-
? Object.assign(Object.assign({}, callResult.error), { message: callResult.error.message }) : ''
|
|
134
|
-
};
|
|
135
|
-
yield taskRepo.pushExecutionResultById({
|
|
136
|
-
id: task.id,
|
|
137
|
-
status: factory.taskStatus.Executed
|
|
138
|
-
}, result, (typeof next === 'function') ? next : undefined);
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
debug('service.task.execute throwed an error. task:', task.name, task.id, 'error:', error === null || error === void 0 ? void 0 : error.name, error === null || error === void 0 ? void 0 : error.message);
|
|
142
|
-
if (typeof error !== 'object') {
|
|
143
|
-
error = { message: String(error) };
|
|
144
|
-
}
|
|
145
|
-
// 実行結果追加
|
|
146
|
-
const result = {
|
|
147
|
-
executedAt: now,
|
|
148
|
-
endDate: new Date(),
|
|
149
|
-
error: Object.assign(Object.assign({}, error), { code: error.code, message: error.message, name: error.name, stack: error.stack })
|
|
150
|
-
};
|
|
151
|
-
// 失敗してもここではステータスを戻さない(Runningのまま待機)
|
|
152
|
-
yield taskRepo.pushExecutionResultById({
|
|
153
|
-
id: task.id,
|
|
154
|
-
status: task.status
|
|
155
|
-
}, result, (typeof next === 'function') ? next : undefined);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
let notification;
|
|
160
|
-
/**
|
|
161
|
-
* add(2025-03-13~)
|
|
162
|
-
*/
|
|
163
|
-
function notifyAbortedTasksByEmail(params) {
|
|
164
|
-
return (repos, settings, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
const { abortedTasksWithoutReport } = settings;
|
|
166
|
-
const abortedTasks = yield repos.task.projectFields(Object.assign({ status: { $eq: factory.taskStatus.Aborted }, dateAborted: { $gte: params.dateAbortedGte } }, (abortedTasksWithoutReport.length > 0)
|
|
167
|
-
? { name: { $nin: abortedTasksWithoutReport } }
|
|
168
|
-
: undefined), []);
|
|
169
|
-
if (abortedTasks.length > 0) {
|
|
170
|
-
if (notification === undefined) {
|
|
171
|
-
notification = yield Promise.resolve().then(() => require('./notification'));
|
|
172
|
-
}
|
|
173
|
-
// 開発者へ報告
|
|
174
|
-
const message = (0, factory_1.tasks2lineNotify)({ tasks: abortedTasks });
|
|
175
|
-
const notifyResult = yield notification.notifyByEmail({
|
|
176
|
-
subject: message.subject, content: message.content,
|
|
177
|
-
logLevel: 'error'
|
|
178
|
-
})({}, credentials);
|
|
179
|
-
debug('notifyResult:', notifyResult);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SendGridCredentials } from '../credentials/sendGrid';
|
|
2
|
+
import type { IExecuteSettings as IMinimumExecuteSettings, INextFunction } from '../eventEmitter/task';
|
|
3
|
+
import * as factory from '../factory';
|
|
4
|
+
import type { IExecutableTask, IExecutableTaskKeys } from '../repo/task';
|
|
5
|
+
import { Settings } from '../settings';
|
|
6
|
+
import { AggregationSettings } from '../settings/aggregation';
|
|
7
|
+
interface ICredentialSettings {
|
|
8
|
+
sendGrid: SendGridCredentials;
|
|
9
|
+
}
|
|
10
|
+
interface IExecuteSettings extends IMinimumExecuteSettings {
|
|
11
|
+
credentials: ICredentialSettings;
|
|
12
|
+
settings: Settings;
|
|
13
|
+
aggregationSettings?: AggregationSettings;
|
|
14
|
+
}
|
|
15
|
+
interface IExecuteOptions {
|
|
16
|
+
executeById: boolean;
|
|
17
|
+
executeByName: boolean;
|
|
18
|
+
}
|
|
19
|
+
type IOperationExecute<T> = (settings: IExecuteSettings, options: IExecuteOptions) => Promise<T>;
|
|
20
|
+
type ICallResult = void | Pick<factory.task.IExecutionResult, 'error'>;
|
|
21
|
+
type ICallableTaskOperation = (task: IExecutableTask<factory.taskName>) => IOperationExecute<ICallResult>;
|
|
22
|
+
/**
|
|
23
|
+
* タスクを実行する
|
|
24
|
+
*/
|
|
25
|
+
declare function executeTask(task: IExecutableTask<factory.taskName>, next?: INextFunction): IOperationExecute<void>;
|
|
26
|
+
export { ICallableTaskOperation, ICallResult, IExecutableTaskKeys, IOperationExecute, executeTask };
|
|
@@ -0,0 +1,98 @@
|
|
|
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.executeTask = executeTask;
|
|
13
|
+
const createDebug = require("debug");
|
|
14
|
+
const moment = require("moment");
|
|
15
|
+
const factory = require("../factory");
|
|
16
|
+
const debug = createDebug('chevre-domain:service:task');
|
|
17
|
+
/**
|
|
18
|
+
* タスクを実行する
|
|
19
|
+
*/
|
|
20
|
+
// tslint:disable-next-line:max-func-body-length
|
|
21
|
+
function executeTask(task, next) {
|
|
22
|
+
const now = new Date();
|
|
23
|
+
debug('executing an executableTask...', task, now);
|
|
24
|
+
return (settings, options) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const taskRepo = new (yield Promise.resolve().then(() => require('../repo/task'))).TaskRepo(settings.connection);
|
|
26
|
+
try {
|
|
27
|
+
// 期限検証(2024-04-23~)
|
|
28
|
+
if (task.expires instanceof Date) {
|
|
29
|
+
const taskExpired = moment(now)
|
|
30
|
+
.isAfter(task.expires);
|
|
31
|
+
if (taskExpired) {
|
|
32
|
+
throw new factory.errors.Internal(`task expired [expires:${task.expires}]`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// タスク名の関数が定義されていなければ、TypeErrorとなる
|
|
36
|
+
let callResult;
|
|
37
|
+
const { call } = yield Promise.resolve(`${`./task/${task.name}`}`).then(s => require(s));
|
|
38
|
+
switch (task.name) {
|
|
39
|
+
case factory.taskName.AcceptCOAOffer:
|
|
40
|
+
case factory.taskName.AggregateOnSystem:
|
|
41
|
+
case factory.taskName.AuthorizePayment:
|
|
42
|
+
case factory.taskName.CancelPendingReservation:
|
|
43
|
+
case factory.taskName.CheckMovieTicket:
|
|
44
|
+
case factory.taskName.DeletePerson:
|
|
45
|
+
case factory.taskName.HandleNotification:
|
|
46
|
+
case factory.taskName.ImportEventCapacitiesFromCOA:
|
|
47
|
+
case factory.taskName.ImportEventsFromCOA:
|
|
48
|
+
case factory.taskName.ImportOffersFromCOA:
|
|
49
|
+
case factory.taskName.InvalidatePaymentUrl:
|
|
50
|
+
case factory.taskName.OnAuthorizationCreated:
|
|
51
|
+
case factory.taskName.Pay:
|
|
52
|
+
case factory.taskName.PublishPaymentUrl:
|
|
53
|
+
case factory.taskName.Refund:
|
|
54
|
+
case factory.taskName.VoidPayTransaction:
|
|
55
|
+
case factory.taskName.VoidReserveTransaction:
|
|
56
|
+
case factory.taskName.ConfirmReserveTransaction:
|
|
57
|
+
case factory.taskName.ReturnPayTransaction:
|
|
58
|
+
case factory.taskName.ReturnReserveTransaction:
|
|
59
|
+
case factory.taskName.SendEmailMessage:
|
|
60
|
+
case factory.taskName.TriggerWebhook:
|
|
61
|
+
callResult = yield call(task)(settings, options);
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
yield call(task.data)(settings);
|
|
65
|
+
}
|
|
66
|
+
const result = {
|
|
67
|
+
executedAt: now,
|
|
68
|
+
endDate: new Date(),
|
|
69
|
+
// enable overwriting task.executionResults.error on Executed(2024-05-29~)
|
|
70
|
+
error: ((callResult === null || callResult === void 0 ? void 0 : callResult.error) instanceof Error)
|
|
71
|
+
? Object.assign(Object.assign({}, callResult.error), { message: callResult.error.message }) : ''
|
|
72
|
+
};
|
|
73
|
+
yield taskRepo.pushExecutionResultById({
|
|
74
|
+
id: task.id,
|
|
75
|
+
status: factory.taskStatus.Executed,
|
|
76
|
+
remainingNumberOfTries: task.remainingNumberOfTries
|
|
77
|
+
}, result, (typeof next === 'function') ? next : undefined);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
debug('service.task.execute throwed an error. task:', task.name, task.id, 'error:', error === null || error === void 0 ? void 0 : error.name, error === null || error === void 0 ? void 0 : error.message);
|
|
81
|
+
if (typeof error !== 'object') {
|
|
82
|
+
error = { message: String(error) };
|
|
83
|
+
}
|
|
84
|
+
// 実行結果追加
|
|
85
|
+
const result = {
|
|
86
|
+
executedAt: now,
|
|
87
|
+
endDate: new Date(),
|
|
88
|
+
error: Object.assign(Object.assign({}, error), { code: error.code, message: error.message, name: error.name, stack: error.stack })
|
|
89
|
+
};
|
|
90
|
+
// 失敗してもここではステータスを戻さない(Runningのまま待機)
|
|
91
|
+
yield taskRepo.pushExecutionResultById({
|
|
92
|
+
id: task.id,
|
|
93
|
+
status: task.status,
|
|
94
|
+
remainingNumberOfTries: task.remainingNumberOfTries
|
|
95
|
+
}, result, (typeof next === 'function') ? next : undefined);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as factory from '../factory';
|
|
2
|
-
import type { ICallableTaskOperation, ICallResult, IOperationExecute } from '../service/
|
|
2
|
+
import type { ICallableTaskOperation, ICallResult, IOperationExecute } from '../service/taskHandler';
|
|
3
3
|
interface IOnOrderStatusChanged {
|
|
4
4
|
informOrder2hub?: factory.project.IInformParams[];
|
|
5
5
|
}
|
package/package.json
CHANGED