@chevre/domain 26.0.0-alpha.19 → 26.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/chevre/repo/adminScheduledTask.d.ts +1 -1
- package/lib/chevre/repo/adminTask.d.ts +2 -2
- package/lib/chevre/repo/adminTask.js +0 -6
- package/lib/chevre/repo/mongoose/schemas/task.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/task.js +16 -33
- package/lib/chevre/repo/scheduledTask.d.ts +4 -1
- package/lib/chevre/repo/scheduledTask.js +3 -4
- package/lib/chevre/repo/task.d.ts +1 -1
- package/lib/chevre/service/asyncAction.js +1 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +1 -1
- 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.js +2 -6
- package/lib/chevre/service/taskHandler/onOperationFailed.js +0 -1
- package/lib/chevre/service/taskHandler.js +2 -11
- package/lib/chevre/taskSettings.d.ts +4 -6
- package/package.json +2 -2
- package/lib/chevre/repo/scheduledTaskMigration.d.ts +0 -27
- package/lib/chevre/repo/scheduledTaskMigration.js +0 -121
|
@@ -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
|
* 予定タスク管理リポジトリ
|
|
@@ -36,13 +36,13 @@ export declare class AdminTaskRepo {
|
|
|
36
36
|
$lt: Date;
|
|
37
37
|
};
|
|
38
38
|
}): Promise<import("mongodb").DeleteResult>;
|
|
39
|
-
getCursor(conditions: FilterQuery<factory.task.ITask<factory.taskName>>, projection: ProjectionType<factory.task.ITask<factory.taskName>>): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> &
|
|
39
|
+
getCursor(conditions: FilterQuery<factory.task.ITask<factory.taskName>>, projection: ProjectionType<factory.task.ITask<factory.taskName>>): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Pick<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask, "name" | "description" | "project" | "identifier" | "data" | "status" | "runsAt" | "dateAborted" | "executionResults" | "executor" | "lastTriedAt" | "remainingNumberOfTries" | "numberOfTried"> & {
|
|
40
40
|
expires?: never;
|
|
41
41
|
} & {
|
|
42
42
|
_id: import("mongoose").Types.ObjectId;
|
|
43
43
|
} & {
|
|
44
44
|
__v: number;
|
|
45
|
-
}, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> &
|
|
45
|
+
}, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Pick<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask, "name" | "description" | "project" | "identifier" | "data" | "status" | "runsAt" | "dateAborted" | "executionResults" | "executor" | "lastTriedAt" | "remainingNumberOfTries" | "numberOfTried"> & {
|
|
46
46
|
expires?: never;
|
|
47
47
|
} & {
|
|
48
48
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -8,9 +8,7 @@ const moment_1 = __importDefault(require("moment"));
|
|
|
8
8
|
const factory_1 = require("../factory");
|
|
9
9
|
const settings_1 = require("../settings");
|
|
10
10
|
const task_1 = require("./mongoose/schemas/task");
|
|
11
|
-
// | 'expires'; // 非同期アクションは移行につきexpires廃止(2026-08-05~)
|
|
12
11
|
const AVAILABLE_PROJECT_FIELDS = [
|
|
13
|
-
'alternateName',
|
|
14
12
|
'identifier',
|
|
15
13
|
'description',
|
|
16
14
|
'project',
|
|
@@ -104,10 +102,6 @@ class AdminTaskRepo {
|
|
|
104
102
|
if (typeof objectPurposeOrderNumberEq === 'string') {
|
|
105
103
|
andConditions.push({ 'data.purpose.orderNumber': { $exists: true, $eq: objectPurposeOrderNumberEq } });
|
|
106
104
|
}
|
|
107
|
-
const alternateNameRegex = params.alternateName?.$regex;
|
|
108
|
-
if (typeof alternateNameRegex === 'string' && alternateNameRegex.length > 0) {
|
|
109
|
-
andConditions.push({ alternateName: { $exists: true, $regex: new RegExp(alternateNameRegex) } });
|
|
110
|
-
}
|
|
111
105
|
const identifierRegex = params.identifier?.$regex;
|
|
112
106
|
if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
|
|
113
107
|
andConditions.push({ identifier: { $exists: true, $regex: new RegExp(identifierRegex) } });
|
|
@@ -1,7 +1,7 @@
|
|
|
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 =
|
|
4
|
+
type IDocType = Pick<factory.task.ITask<factory.taskName>, 'data' | 'dateAborted' | 'description' | 'executionResults' | 'executor' | 'identifier' | 'lastTriedAt' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'> & {
|
|
5
5
|
expires?: never;
|
|
6
6
|
};
|
|
7
7
|
type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
|
|
@@ -8,7 +8,6 @@ const settings_1 = require("../../../settings");
|
|
|
8
8
|
const modelName = 'Task';
|
|
9
9
|
exports.modelName = modelName;
|
|
10
10
|
const schemaDefinition = {
|
|
11
|
-
alternateName: String, // add(2025-03-28~)
|
|
12
11
|
identifier: String,
|
|
13
12
|
description: String, // add(2025-03-30~)
|
|
14
13
|
project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
@@ -22,6 +21,7 @@ const schemaDefinition = {
|
|
|
22
21
|
executor: mongoose_1.SchemaTypes.Mixed,
|
|
23
22
|
data: mongoose_1.SchemaTypes.Mixed,
|
|
24
23
|
dateAborted: Date,
|
|
24
|
+
// alternateName: String, // add(2025-03-28~) // identidfier移行完了につき廃止(2026-08-07~)
|
|
25
25
|
// expires: Date // add(2024-04-23~) // 非同期アクションは移行につきexpires廃止(2026-08-05~)
|
|
26
26
|
};
|
|
27
27
|
const schemaOptions = {
|
|
@@ -93,16 +93,6 @@ const indexes = [
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
],
|
|
96
|
-
// 非同期アクションは移行につきexpires廃止(2026-08-05~)
|
|
97
|
-
// [
|
|
98
|
-
// { expires: 1, runsAt: -1 },
|
|
99
|
-
// {
|
|
100
|
-
// name: 'expires',
|
|
101
|
-
// partialFilterExpression: {
|
|
102
|
-
// expires: { $exists: true }
|
|
103
|
-
// }
|
|
104
|
-
// }
|
|
105
|
-
// ],
|
|
106
96
|
[
|
|
107
97
|
{ remainingNumberOfTries: 1, runsAt: -1 },
|
|
108
98
|
{ name: 'searchByRemainingNumberOfTries-v2' }
|
|
@@ -200,27 +190,6 @@ const indexes = [
|
|
|
200
190
|
}
|
|
201
191
|
}
|
|
202
192
|
],
|
|
203
|
-
// 非同期アクションは移行につきexpires廃止(2026-08-05~)
|
|
204
|
-
// [
|
|
205
|
-
// { status: 1, expires: 1 },
|
|
206
|
-
// {
|
|
207
|
-
// name: 'makeExpiredMany',
|
|
208
|
-
// partialFilterExpression: {
|
|
209
|
-
// expires: { $exists: true }
|
|
210
|
-
// }
|
|
211
|
-
// }
|
|
212
|
-
// ],
|
|
213
|
-
[
|
|
214
|
-
// add unique index(2025-03-28~)
|
|
215
|
-
{ alternateName: 1 },
|
|
216
|
-
{
|
|
217
|
-
unique: true,
|
|
218
|
-
name: 'uniqueAlternateName',
|
|
219
|
-
partialFilterExpression: {
|
|
220
|
-
alternateName: { $exists: true }
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
],
|
|
224
193
|
// add unique index(dev)(2025-03-28~)
|
|
225
194
|
// add unique index(test,prod)(2026-07-08~)
|
|
226
195
|
[
|
|
@@ -232,7 +201,21 @@ const indexes = [
|
|
|
232
201
|
identifier: { $exists: true }
|
|
233
202
|
}
|
|
234
203
|
}
|
|
235
|
-
]
|
|
204
|
+
],
|
|
205
|
+
// alternateNameへのインデックスはおそらくもう不要(2026-08-07~)
|
|
206
|
+
// dev,testではインデックス削除済(2026-08-07)
|
|
207
|
+
// prodでは削除予定(2026-08-??)
|
|
208
|
+
// [
|
|
209
|
+
// // add unique index(2025-03-28~)
|
|
210
|
+
// { alternateName: 1 },
|
|
211
|
+
// {
|
|
212
|
+
// unique: true,
|
|
213
|
+
// name: 'uniqueAlternateName',
|
|
214
|
+
// partialFilterExpression: {
|
|
215
|
+
// alternateName: { $exists: true }
|
|
216
|
+
// }
|
|
217
|
+
// }
|
|
218
|
+
// ],
|
|
236
219
|
];
|
|
237
220
|
exports.indexes = indexes;
|
|
238
221
|
/**
|
|
@@ -64,11 +64,14 @@ export declare class ScheduledTaskRepo {
|
|
|
64
64
|
status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
|
|
65
65
|
executionResult: factory.task.IExecutionResult;
|
|
66
66
|
}): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* cron:createImportEventCapacitiesTasksでの新タスク作成前に使用する
|
|
69
|
+
*/
|
|
67
70
|
deleteTooOldReadyTasks(params: {
|
|
68
71
|
project: {
|
|
69
72
|
id: string;
|
|
70
73
|
};
|
|
71
|
-
name: factory.taskName;
|
|
74
|
+
name: factory.taskName.ImportEventCapacitiesFromCOA;
|
|
72
75
|
runsAt: {
|
|
73
76
|
$lt: Date;
|
|
74
77
|
};
|
|
@@ -71,7 +71,6 @@ class ScheduledTaskRepo {
|
|
|
71
71
|
if (!(params.runsAt.$lt instanceof Date)) {
|
|
72
72
|
throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
73
73
|
}
|
|
74
|
-
// const { noEmitEvent } = options;
|
|
75
74
|
const projection = {
|
|
76
75
|
_id: 0,
|
|
77
76
|
id: { $toString: '$_id' },
|
|
@@ -97,9 +96,6 @@ class ScheduledTaskRepo {
|
|
|
97
96
|
new: true,
|
|
98
97
|
projection,
|
|
99
98
|
sort: { runsAt: factory_1.factory.sortType.Ascending } // ソートは、実行日時で固定化(2026-07-31~)
|
|
100
|
-
// ...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
|
|
101
|
-
// ? { sort: params.sort }
|
|
102
|
-
// : undefined
|
|
103
99
|
})
|
|
104
100
|
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
105
101
|
.lean()
|
|
@@ -141,6 +137,9 @@ class ScheduledTaskRepo {
|
|
|
141
137
|
})
|
|
142
138
|
.exec();
|
|
143
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* cron:createImportEventCapacitiesTasksでの新タスク作成前に使用する
|
|
142
|
+
*/
|
|
144
143
|
async deleteTooOldReadyTasks(params) {
|
|
145
144
|
return this.scheduledTaskModel.deleteMany({
|
|
146
145
|
'project.id': { $eq: params.project.id },
|
|
@@ -39,7 +39,7 @@ export declare class TaskRepo {
|
|
|
39
39
|
reservationFor: {
|
|
40
40
|
id: string;
|
|
41
41
|
};
|
|
42
|
-
}): Promise<(import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> &
|
|
42
|
+
}): Promise<(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
43
|
expires?: never;
|
|
44
44
|
} & {
|
|
45
45
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -27,10 +27,7 @@ function executeAsyncActionById(params, next) {
|
|
|
27
27
|
}
|
|
28
28
|
// タスクがなければ終了
|
|
29
29
|
if (task !== null) {
|
|
30
|
-
await (0, asyncActionHandler_1.executeAsyncAction)(task, next)(settings, {
|
|
31
|
-
executeById: true,
|
|
32
|
-
// executeByName: false // discontinue(2026-08-05~)
|
|
33
|
-
});
|
|
30
|
+
await (0, asyncActionHandler_1.executeAsyncAction)(task, next)(settings, {});
|
|
34
31
|
}
|
|
35
32
|
};
|
|
36
33
|
}
|
|
@@ -5,7 +5,7 @@ type IProcessingOrder = Pick<factory.order.IOrder, 'id' | 'orderNumber' | 'broke
|
|
|
5
5
|
numAcceptedOffers: number;
|
|
6
6
|
orderStatus: factory.orderStatus.OrderProcessing;
|
|
7
7
|
};
|
|
8
|
-
type ICreatingCheckResourceTask = Pick<factory.task.checkResource.IAttributes, '
|
|
8
|
+
type ICreatingCheckResourceTask = Pick<factory.task.checkResource.IAttributes, 'data' | 'executionResults' | 'identifier' | 'name' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'status'> & {
|
|
9
9
|
alternateName?: never;
|
|
10
10
|
identifier: string;
|
|
11
11
|
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { IExecuteSettings as IMinimumExecuteSettings, IRunningTask } from '../eventEmitter/task';
|
|
2
|
-
|
|
3
|
-
interface IExecuteSettings extends IMinimumExecuteSettings {
|
|
4
|
-
aggregationSettings?: AggregationSettings;
|
|
5
|
-
}
|
|
2
|
+
type IExecuteSettings = IMinimumExecuteSettings;
|
|
6
3
|
type IOperation<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
7
4
|
/**
|
|
8
5
|
* Runningの予定タスクを実行する
|
|
@@ -19,22 +19,15 @@ function executeScheduledTaskById(params) {
|
|
|
19
19
|
const { id } = params;
|
|
20
20
|
let task = null;
|
|
21
21
|
try {
|
|
22
|
-
task = await scheduledTaskRepo.findRunningScheduledTaskById({
|
|
23
|
-
id,
|
|
24
|
-
// status,
|
|
25
|
-
// executor: { name: executor.name }
|
|
26
|
-
});
|
|
22
|
+
task = await scheduledTaskRepo.findRunningScheduledTaskById({ id });
|
|
27
23
|
}
|
|
28
24
|
catch (error) {
|
|
29
25
|
/* istanbul ignore next */
|
|
30
|
-
debug('
|
|
26
|
+
debug('scheduledTaskRepo.findRunningScheduledTaskById error:', error);
|
|
31
27
|
}
|
|
32
28
|
// タスクがなければ終了
|
|
33
29
|
if (task !== null) {
|
|
34
|
-
await (0, scheduledTaskHandler_1.executeScheduledTask)(task)(settings, {
|
|
35
|
-
executeById: true,
|
|
36
|
-
// executeByName: false // discontinue(2026-08-05~)
|
|
37
|
-
});
|
|
30
|
+
await (0, scheduledTaskHandler_1.executeScheduledTask)(task)(settings, {});
|
|
38
31
|
}
|
|
39
32
|
};
|
|
40
33
|
}
|
|
@@ -13,7 +13,7 @@ function onOperationFailed(params) {
|
|
|
13
13
|
error = { message: String(error) };
|
|
14
14
|
}
|
|
15
15
|
const endDate = new Date();
|
|
16
|
-
// remainingNumberOfTries<=0ならAborted
|
|
16
|
+
// remainingNumberOfTries<=0ならAborted
|
|
17
17
|
const isRetryable = task.remainingNumberOfTries > 0;
|
|
18
18
|
if (isRetryable) {
|
|
19
19
|
const result = {
|
|
@@ -35,7 +35,6 @@ function onOperationFailed(params) {
|
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
// 予定タスクは分析連携不要
|
|
38
|
-
// await informTaskIfNeeded({ task, executionEndDate: endDate })(repos);
|
|
39
38
|
const result = {
|
|
40
39
|
executedAt: now,
|
|
41
40
|
endDate,
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.taskLoader = void 0;
|
|
7
4
|
exports.executeScheduledTask = executeScheduledTask;
|
|
8
|
-
const debug_1 = __importDefault(require("debug"));
|
|
9
5
|
const factory_1 = require("../factory");
|
|
10
6
|
const onOperationFailed_1 = require("./scheduledTaskHandler/onOperationFailed");
|
|
11
|
-
const debug = (0, debug_1.default)('chevre-domain:service:scheduledTaskHandler');
|
|
12
7
|
exports.taskLoader = {
|
|
13
8
|
load: (taskName) => {
|
|
14
9
|
return import(`./task/${taskName}.js`);
|
|
@@ -19,18 +14,10 @@ exports.taskLoader = {
|
|
|
19
14
|
*/
|
|
20
15
|
function executeScheduledTask(task) {
|
|
21
16
|
const now = new Date();
|
|
22
|
-
debug('executing an executableTask...', task, now);
|
|
23
17
|
return async (settings, options) => {
|
|
24
18
|
const scheduledTaskRepo = new (await import('../repo/scheduledTask.js')).ScheduledTaskRepo(settings.connection);
|
|
25
19
|
try {
|
|
26
20
|
// 予定タスクのexpiresはDBのttl基準なので期限検証はしない
|
|
27
|
-
// if (task.expires instanceof Date) {
|
|
28
|
-
// const taskExpired: boolean = moment(now)
|
|
29
|
-
// .isAfter(task.expires);
|
|
30
|
-
// if (taskExpired) {
|
|
31
|
-
// throw new factory.errors.Internal(`task expired [expires:${task.expires}]`);
|
|
32
|
-
// }
|
|
33
|
-
// }
|
|
34
21
|
// remainingNumberOfTries<0ならcallを実行しない(2025-08-04~)
|
|
35
22
|
// リトライを繰り返した後、不明の原因でRunningのまま残ってしまったタスクがリトライされたケース
|
|
36
23
|
const { remainingNumberOfTries } = task;
|
|
@@ -23,8 +23,7 @@ function executeTaskById(params) {
|
|
|
23
23
|
task = await taskRunningRepo.executeOneById({
|
|
24
24
|
id,
|
|
25
25
|
status,
|
|
26
|
-
executor: { name: executor.name }
|
|
27
|
-
// ...(expires instanceof Date) ? { expires } : undefined // 非同期アクションは移行につきexpires廃止(2026-08-05~)
|
|
26
|
+
executor: { name: executor.name }
|
|
28
27
|
});
|
|
29
28
|
}
|
|
30
29
|
catch (error) {
|
|
@@ -33,10 +32,7 @@ function executeTaskById(params) {
|
|
|
33
32
|
}
|
|
34
33
|
// タスクがなければ終了
|
|
35
34
|
if (task !== null) {
|
|
36
|
-
await (0, taskHandler_1.executeTask)(task)(settings, {
|
|
37
|
-
executeById: true,
|
|
38
|
-
// executeByName: false // discontinue(2026-08-05~)
|
|
39
|
-
});
|
|
35
|
+
await (0, taskHandler_1.executeTask)(task)(settings, {});
|
|
40
36
|
}
|
|
41
37
|
};
|
|
42
38
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.onOperationFailed = onOperationFailed;
|
|
4
|
-
// import type { INextFunction } from '../../eventEmitter/task';
|
|
5
4
|
const factory_1 = require("../../factory");
|
|
6
5
|
const informTaskIfNeeded_1 = require("./onOperationFailed/informTaskIfNeeded");
|
|
7
6
|
/**
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.taskLoader = void 0;
|
|
7
7
|
exports.executeTask = executeTask;
|
|
8
8
|
const debug_1 = __importDefault(require("debug"));
|
|
9
|
-
const moment_1 = __importDefault(require("moment"));
|
|
10
9
|
const factory_1 = require("../factory");
|
|
11
10
|
const onOperationFailed_1 = require("./taskHandler/onOperationFailed");
|
|
12
11
|
const debug = (0, debug_1.default)('chevre-domain:service:taskHandler');
|
|
@@ -26,14 +25,7 @@ function executeTask(task) {
|
|
|
26
25
|
const taskRepo = new (await import('../repo/task.js')).TaskRepo(settings.connection);
|
|
27
26
|
const taskRunningRepo = new (await import('../repo/taskRunning.js')).TaskRunningRepo(settings.connection);
|
|
28
27
|
try {
|
|
29
|
-
//
|
|
30
|
-
if (task.expires instanceof Date) {
|
|
31
|
-
const taskExpired = (0, moment_1.default)(now)
|
|
32
|
-
.isAfter(task.expires);
|
|
33
|
-
if (taskExpired) {
|
|
34
|
-
throw new factory_1.factory.errors.Internal(`task expired [expires:${task.expires}]`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
28
|
+
// タスクのexpiresは廃止済なので期限検証はなし(2026-08-07~)
|
|
37
29
|
// remainingNumberOfTries<0ならcallを実行しない(2025-08-04~)
|
|
38
30
|
// リトライを繰り返した後、不明の原因でRunningのまま残ってしまったタスクがリトライされたケース
|
|
39
31
|
const { remainingNumberOfTries } = task;
|
|
@@ -63,8 +55,7 @@ function executeTask(task) {
|
|
|
63
55
|
}
|
|
64
56
|
catch (error) {
|
|
65
57
|
await (0, onOperationFailed_1.onOperationFailed)({
|
|
66
|
-
task, now, error
|
|
67
|
-
// ...(typeof next === 'function') ? { next } : undefined // discontinue next(2026-08-05~)
|
|
58
|
+
task, now, error
|
|
68
59
|
})({ setting: settingRepo, task: taskRepo, taskRunning: taskRunningRepo });
|
|
69
60
|
}
|
|
70
61
|
};
|
|
@@ -20,12 +20,10 @@ declare class AggregationSettings {
|
|
|
20
20
|
interface IExecuteSettings extends IMinimumExecuteSettings {
|
|
21
21
|
aggregationSettings?: AggregationSettings;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
executeById: true;
|
|
28
|
-
}
|
|
23
|
+
/**
|
|
24
|
+
* かつてはexecuteById,executeByNameといったオプションが存在したが、現時点で特に何もなし(2026-08-07)
|
|
25
|
+
*/
|
|
26
|
+
type IExecuteOptions = Record<string, never>;
|
|
29
27
|
type IOperationExecute<T> = (settings: IExecuteSettings, options: IExecuteOptions) => Promise<T>;
|
|
30
28
|
type ICallResult = void | Pick<factory.task.IExecutionResult, 'error'>;
|
|
31
29
|
type ICallableTaskOperation = (task: IExecutableTask<factory.taskName>) => IOperationExecute<ICallResult>;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cognito-identity-provider": "3.1090.0",
|
|
13
13
|
"@aws-sdk/credential-providers": "3.1090.0",
|
|
14
|
-
"@chevre/factory": "10.
|
|
14
|
+
"@chevre/factory": "10.2.0",
|
|
15
15
|
"@motionpicture/coa-service": "10.0.0",
|
|
16
16
|
"@motionpicture/gmo-service": "6.1.0-alpha.0",
|
|
17
17
|
"@sendgrid/client": "8.1.4",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"postversion": "git push origin --tags",
|
|
89
89
|
"prepublishOnly": "npm run clean && npm run build"
|
|
90
90
|
},
|
|
91
|
-
"version": "26.0.0-alpha.
|
|
91
|
+
"version": "26.0.0-alpha.20"
|
|
92
92
|
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Connection } from 'mongoose';
|
|
2
|
-
/**
|
|
3
|
-
* 予定タスク移行リポジトリ
|
|
4
|
-
*/
|
|
5
|
-
export declare class ScheduledTaskMigrationRepo {
|
|
6
|
-
private readonly scheduledTaskModel;
|
|
7
|
-
private readonly taskModel;
|
|
8
|
-
constructor(connection: Connection);
|
|
9
|
-
/**
|
|
10
|
-
* DeleteTransactionタスク移行処理
|
|
11
|
-
*/
|
|
12
|
-
migrateDeleteTransactionTasks(params: {
|
|
13
|
-
limit: number;
|
|
14
|
-
runsAtGte: Date;
|
|
15
|
-
expiresInDays: number;
|
|
16
|
-
}): Promise<(import("mongodb").BulkWriteResult & {
|
|
17
|
-
mongoose?: {
|
|
18
|
-
validationErrors: import("mongoose").Error[];
|
|
19
|
-
} | undefined;
|
|
20
|
-
}) | undefined>;
|
|
21
|
-
deleteLagacyTasks(params: {
|
|
22
|
-
limit: number;
|
|
23
|
-
}): Promise<import("mongodb").DeleteResult | undefined>;
|
|
24
|
-
deleteLagacyAsyncActions(params: {
|
|
25
|
-
limit: number;
|
|
26
|
-
}): Promise<import("mongodb").DeleteResult | undefined>;
|
|
27
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ScheduledTaskMigrationRepo = void 0;
|
|
7
|
-
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
const factory_1 = require("../factory");
|
|
9
|
-
const scheduledTasks_1 = require("./mongoose/schemas/scheduledTasks");
|
|
10
|
-
const task_1 = require("./mongoose/schemas/task");
|
|
11
|
-
/**
|
|
12
|
-
* 予定タスク移行リポジトリ
|
|
13
|
-
*/
|
|
14
|
-
class ScheduledTaskMigrationRepo {
|
|
15
|
-
scheduledTaskModel;
|
|
16
|
-
taskModel;
|
|
17
|
-
constructor(connection) {
|
|
18
|
-
this.scheduledTaskModel = connection.model(scheduledTasks_1.modelName, (0, scheduledTasks_1.createSchema)());
|
|
19
|
-
this.taskModel = connection.model(task_1.modelName, (0, task_1.createSchema)());
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* DeleteTransactionタスク移行処理
|
|
23
|
-
*/
|
|
24
|
-
async migrateDeleteTransactionTasks(params) {
|
|
25
|
-
const { limit, runsAtGte, expiresInDays } = params;
|
|
26
|
-
// limit件抽出
|
|
27
|
-
const migratingTasks = await this.taskModel.find({
|
|
28
|
-
// _id: { $eq: '6a66e83f9b21f3d4bf5fa232' },
|
|
29
|
-
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
30
|
-
name: { $eq: factory_1.factory.taskName.DeleteTransaction },
|
|
31
|
-
runsAt: { $gte: runsAtGte }
|
|
32
|
-
})
|
|
33
|
-
.limit(limit)
|
|
34
|
-
.lean()
|
|
35
|
-
.exec();
|
|
36
|
-
if (migratingTasks.length === 0) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
;
|
|
40
|
-
const bulkOps = migratingTasks.map((migratingTask) => {
|
|
41
|
-
return {
|
|
42
|
-
updateOne: {
|
|
43
|
-
filter: {
|
|
44
|
-
_id: { $eq: migratingTask._id }
|
|
45
|
-
},
|
|
46
|
-
update: {
|
|
47
|
-
$setOnInsert: {
|
|
48
|
-
...migratingTask,
|
|
49
|
-
expires: (0, moment_1.default)(migratingTask.runsAt)
|
|
50
|
-
.add(expiresInDays, 'days')
|
|
51
|
-
.toDate()
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
upsert: true
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
// 新コレクションへ挿入
|
|
59
|
-
const result = await this.scheduledTaskModel.bulkWrite(bulkOps, { ordered: false });
|
|
60
|
-
// 新コレクションへ書き込めたIDだけを旧DBから削除
|
|
61
|
-
const successfulIds = [];
|
|
62
|
-
migratingTasks.forEach(d => successfulIds.push(d._id));
|
|
63
|
-
if (successfulIds.length > 0) {
|
|
64
|
-
await this.taskModel.deleteMany({ _id: { $in: successfulIds } })
|
|
65
|
-
.exec();
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
async deleteLagacyTasks(params) {
|
|
70
|
-
const { limit } = params;
|
|
71
|
-
const deletingTasks = await this.taskModel.find({
|
|
72
|
-
name: {
|
|
73
|
-
$in: [
|
|
74
|
-
factory_1.factory.taskName.DeleteTransaction,
|
|
75
|
-
factory_1.factory.taskName.ImportEventsFromCOA,
|
|
76
|
-
factory_1.factory.taskName.ImportEventCapacitiesFromCOA
|
|
77
|
-
]
|
|
78
|
-
}
|
|
79
|
-
}, { _id: 1 })
|
|
80
|
-
.limit(limit)
|
|
81
|
-
.lean()
|
|
82
|
-
.exec();
|
|
83
|
-
// console.log(deletingTasks);
|
|
84
|
-
if (deletingTasks.length === 0) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
;
|
|
88
|
-
return this.taskModel.deleteMany({
|
|
89
|
-
_id: { $in: deletingTasks.map((doc) => doc._id) }
|
|
90
|
-
})
|
|
91
|
-
.exec();
|
|
92
|
-
}
|
|
93
|
-
async deleteLagacyAsyncActions(params) {
|
|
94
|
-
const { limit } = params;
|
|
95
|
-
const deletingTasks = await this.taskModel.find({
|
|
96
|
-
name: {
|
|
97
|
-
$in: [
|
|
98
|
-
factory_1.factory.taskName.AcceptCOAOffer,
|
|
99
|
-
factory_1.factory.taskName.AuthorizePayment,
|
|
100
|
-
factory_1.factory.taskName.CheckMovieTicket,
|
|
101
|
-
factory_1.factory.taskName.PublishPaymentUrl,
|
|
102
|
-
factory_1.factory.taskName.VoidReserveTransaction
|
|
103
|
-
]
|
|
104
|
-
},
|
|
105
|
-
expires: { $exists: true, $lte: new Date() }
|
|
106
|
-
}, { _id: 1 })
|
|
107
|
-
.limit(limit)
|
|
108
|
-
.lean()
|
|
109
|
-
.exec();
|
|
110
|
-
// console.log(deletingTasks);
|
|
111
|
-
if (deletingTasks.length === 0) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
;
|
|
115
|
-
return this.taskModel.deleteMany({
|
|
116
|
-
_id: { $in: deletingTasks.map((doc) => doc._id) }
|
|
117
|
-
})
|
|
118
|
-
.exec();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.ScheduledTaskMigrationRepo = ScheduledTaskMigrationRepo;
|