@chevre/domain 26.0.0-alpha.12 → 26.0.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/lib/chevre/repo/adminTask.d.ts +15 -3
- package/lib/chevre/repo/adminTask.js +26 -1
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +1 -2
- package/lib/chevre/repo/mongoose/schemas/task.d.ts +1 -4
- package/lib/chevre/repo/mongoose/schemas/task.js +5 -1
- package/lib/chevre/repo/task.d.ts +4 -74
- package/lib/chevre/repo/task.js +11 -189
- package/lib/chevre/repo/taskDelayed.d.ts +67 -0
- package/lib/chevre/repo/taskDelayed.js +148 -0
- package/lib/chevre/repository.d.ts +5 -10
- package/lib/chevre/repository.js +11 -22
- package/lib/chevre/service/asyncAction.js +1 -1
- package/lib/chevre/service/scheduledTask.js +1 -1
- package/lib/chevre/service/task/acceptCOAOffer.js +1 -14
- package/lib/chevre/service/task/authorizePayment.js +1 -7
- package/lib/chevre/service/task/checkMovieTicket.js +1 -7
- package/lib/chevre/service/task/publishPaymentUrl.js +1 -10
- package/lib/chevre/service/task/syncResourcesFromCOA.js +1 -5
- package/lib/chevre/service/task/voidReserveTransaction.js +5 -8
- package/lib/chevre/service/task.d.ts +4 -4
- package/lib/chevre/service/task.js +7 -7
- package/lib/chevre/service/taskHandler/onOperationFailed.d.ts +1 -2
- package/lib/chevre/service/taskHandler/onOperationFailed.js +8 -7
- package/lib/chevre/service/taskHandler.d.ts +1 -2
- package/lib/chevre/service/taskHandler.js +6 -5
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +1 -1
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +11 -17
- package/lib/chevre/service/transaction/returnOrder.js +11 -17
- package/lib/chevre/taskSettings.d.ts +4 -2
- package/package.json +1 -1
- package/lib/chevre/repo/asyncActionLegacy.d.ts +0 -23
- package/lib/chevre/repo/asyncActionLegacy.js +0 -59
- package/lib/chevre/repo/scheduledTaskLegacy.d.ts +0 -39
- package/lib/chevre/repo/scheduledTaskLegacy.js +0 -96
|
@@ -7,6 +7,7 @@ exports.taskLoader = void 0;
|
|
|
7
7
|
exports.executeTask = executeTask;
|
|
8
8
|
const debug_1 = __importDefault(require("debug"));
|
|
9
9
|
const moment_1 = __importDefault(require("moment"));
|
|
10
|
+
// import type { INextFunction } from '../eventEmitter/task';
|
|
10
11
|
const factory_1 = require("../factory");
|
|
11
12
|
const onOperationFailed_1 = require("./taskHandler/onOperationFailed");
|
|
12
13
|
const debug = (0, debug_1.default)('chevre-domain:service:taskHandler');
|
|
@@ -18,7 +19,7 @@ exports.taskLoader = {
|
|
|
18
19
|
/**
|
|
19
20
|
* タスクを実行する
|
|
20
21
|
*/
|
|
21
|
-
function executeTask(task
|
|
22
|
+
function executeTask(task) {
|
|
22
23
|
const now = new Date();
|
|
23
24
|
debug('executing an executableTask...', task, now);
|
|
24
25
|
return async (settings, options) => {
|
|
@@ -57,17 +58,17 @@ function executeTask(task, next) {
|
|
|
57
58
|
};
|
|
58
59
|
await taskRepo.setExecutionResultAndStatus({
|
|
59
60
|
id: task.id,
|
|
60
|
-
remainingNumberOfTries,
|
|
61
|
-
name: task.name
|
|
61
|
+
// remainingNumberOfTries,
|
|
62
|
+
// name: task.name
|
|
62
63
|
}, {
|
|
63
64
|
status: factory_1.factory.taskStatus.Executed,
|
|
64
65
|
executionResult: result
|
|
65
|
-
}
|
|
66
|
+
});
|
|
66
67
|
}
|
|
67
68
|
catch (error) {
|
|
68
69
|
await (0, onOperationFailed_1.onOperationFailed)({
|
|
69
70
|
task, now, error,
|
|
70
|
-
...(typeof next === 'function') ? { next } : undefined
|
|
71
|
+
// ...(typeof next === 'function') ? { next } : undefined // discontinue next(2026-08-05~)
|
|
71
72
|
})({ setting: settingRepo, task: taskRepo });
|
|
72
73
|
}
|
|
73
74
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { factory } from '../../../../factory';
|
|
2
2
|
import type { ISetting } from '../../../../repo/setting';
|
|
3
|
-
type IPlaceOrderPotentialTask = factory.task.IAttributes<factory.taskName.PlaceOrder> | factory.task.IAttributes<factory.taskName.VoidPayTransaction> | factory.task.voidReserveTransaction.IAttributes
|
|
3
|
+
type IPlaceOrderPotentialTask = factory.task.IAttributes<factory.taskName.PlaceOrder> | factory.task.IAttributes<factory.taskName.VoidPayTransaction> | Omit<factory.task.voidReserveTransaction.IAttributes, 'expires'>;
|
|
4
4
|
/**
|
|
5
5
|
* 取引のタスクを作成する
|
|
6
6
|
* 取引削除タスクを分離(2026-08-02~)
|
|
@@ -25,24 +25,18 @@ function exportTasksById(params) {
|
|
|
25
25
|
}
|
|
26
26
|
// search settings
|
|
27
27
|
const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
|
|
28
|
-
const useScheduledDeleteTransactionTask = setting?.storage?.useScheduledDeleteTransactionTask === true;
|
|
29
28
|
const deleteTransactionTaskExpiresInDays = setting?.storage?.deleteTransactionTaskExpiresInDays;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// support scheduledTask(2026-08-02~)
|
|
33
|
-
await repos.task.saveMany((0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }));
|
|
34
|
-
await repos.scheduledTask.addScheduledTasks([{
|
|
35
|
-
...deleteTask,
|
|
36
|
-
expires: (0, moment_1.default)(deleteTask.runsAt)
|
|
37
|
-
.add(deleteTransactionTaskExpiresInDays, 'days')
|
|
38
|
-
.toDate()
|
|
39
|
-
}]);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
await repos.task.saveMany([
|
|
43
|
-
...(0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }),
|
|
44
|
-
deleteTask
|
|
45
|
-
]);
|
|
29
|
+
if (typeof deleteTransactionTaskExpiresInDays !== 'number') {
|
|
30
|
+
throw new factory_1.factory.errors.Internal('settings.storage.deleteTransactionTaskExpiresInDays required');
|
|
46
31
|
}
|
|
32
|
+
const deleteTask = (0, factory_2.createScheduledTasks)({ transaction }, setting);
|
|
33
|
+
// support scheduledTask(2026-08-02~)
|
|
34
|
+
await repos.task.saveMany((0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }));
|
|
35
|
+
await repos.scheduledTask.addScheduledTasks([{
|
|
36
|
+
...deleteTask,
|
|
37
|
+
expires: (0, moment_1.default)(deleteTask.runsAt)
|
|
38
|
+
.add(deleteTransactionTaskExpiresInDays, 'days')
|
|
39
|
+
.toDate()
|
|
40
|
+
}]);
|
|
47
41
|
};
|
|
48
42
|
}
|
|
@@ -167,24 +167,18 @@ function exportTasksById(params) {
|
|
|
167
167
|
}
|
|
168
168
|
// search settings
|
|
169
169
|
const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
|
|
170
|
-
const useScheduledDeleteTransactionTask = setting?.storage?.useScheduledDeleteTransactionTask === true;
|
|
171
170
|
const deleteTransactionTaskExpiresInDays = setting?.storage?.deleteTransactionTaskExpiresInDays;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
// support scheduledTask(2026-08-02~)
|
|
175
|
-
await repos.task.saveMany((0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }));
|
|
176
|
-
await repos.scheduledTask.addScheduledTasks([{
|
|
177
|
-
...deleteTask,
|
|
178
|
-
expires: (0, moment_timezone_1.default)(deleteTask.runsAt)
|
|
179
|
-
.add(deleteTransactionTaskExpiresInDays, 'days')
|
|
180
|
-
.toDate()
|
|
181
|
-
}]);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
await repos.task.saveMany([
|
|
185
|
-
...(0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }),
|
|
186
|
-
deleteTask
|
|
187
|
-
]);
|
|
171
|
+
if (typeof deleteTransactionTaskExpiresInDays !== 'number') {
|
|
172
|
+
throw new factory_1.factory.errors.Internal('settings.storage.deleteTransactionTaskExpiresInDays required');
|
|
188
173
|
}
|
|
174
|
+
const deleteTask = (0, factory_2.createScheduledTasks)({ transaction }, setting);
|
|
175
|
+
// support scheduledTask(2026-08-02~)
|
|
176
|
+
await repos.task.saveMany((0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }));
|
|
177
|
+
await repos.scheduledTask.addScheduledTasks([{
|
|
178
|
+
...deleteTask,
|
|
179
|
+
expires: (0, moment_timezone_1.default)(deleteTask.runsAt)
|
|
180
|
+
.add(deleteTransactionTaskExpiresInDays, 'days')
|
|
181
|
+
.toDate()
|
|
182
|
+
}]);
|
|
189
183
|
};
|
|
190
184
|
}
|
|
@@ -21,8 +21,10 @@ interface IExecuteSettings extends IMinimumExecuteSettings {
|
|
|
21
21
|
aggregationSettings?: AggregationSettings;
|
|
22
22
|
}
|
|
23
23
|
interface IExecuteOptions {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* 現時点(2026-08-05)でリトライタスク、予定タスク、非同期アクション、全てID指定でしか実行されない
|
|
26
|
+
*/
|
|
27
|
+
executeById: true;
|
|
26
28
|
}
|
|
27
29
|
type IOperationExecute<T> = (settings: IExecuteSettings, options: IExecuteOptions) => Promise<T>;
|
|
28
30
|
type ICallResult = void | Pick<factory.task.IExecutionResult, 'error'>;
|
package/package.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Connection, UpdateWriteOpResult } from 'mongoose';
|
|
2
|
-
import { INextFunction } from '../eventEmitter/task';
|
|
3
|
-
import { factory } from '../factory';
|
|
4
|
-
/**
|
|
5
|
-
* 旧非同期アクション(tasksコレクションにて管理)リポジトリ
|
|
6
|
-
*/
|
|
7
|
-
export declare class AsyncActionLegacyRepo {
|
|
8
|
-
private readonly taskModel;
|
|
9
|
-
constructor(connection: Connection);
|
|
10
|
-
runImmediately(params: Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'name' | 'project' | 'remainingNumberOfTries' | 'runsAt'> & {
|
|
11
|
-
alternateName?: never;
|
|
12
|
-
identifier?: never;
|
|
13
|
-
expires: Date;
|
|
14
|
-
}, next: INextFunction): Promise<{
|
|
15
|
-
id: string;
|
|
16
|
-
}>;
|
|
17
|
-
/**
|
|
18
|
-
* Readyのままで期限切れのタスクをExpiredに変更する
|
|
19
|
-
*/
|
|
20
|
-
makeExpiredMany(params: {
|
|
21
|
-
expiresLt: Date;
|
|
22
|
-
}): Promise<UpdateWriteOpResult>;
|
|
23
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AsyncActionLegacyRepo = void 0;
|
|
4
|
-
const task_1 = require("../eventEmitter/task");
|
|
5
|
-
const factory_1 = require("../factory");
|
|
6
|
-
const task_2 = require("./mongoose/schemas/task");
|
|
7
|
-
/**
|
|
8
|
-
* 旧非同期アクション(tasksコレクションにて管理)リポジトリ
|
|
9
|
-
*/
|
|
10
|
-
class AsyncActionLegacyRepo {
|
|
11
|
-
taskModel;
|
|
12
|
-
constructor(connection) {
|
|
13
|
-
this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
|
|
14
|
-
}
|
|
15
|
-
async runImmediately(params,
|
|
16
|
-
// support customr function(2025-05-25~)
|
|
17
|
-
next) {
|
|
18
|
-
const { expires } = params;
|
|
19
|
-
if (!(expires instanceof Date)) {
|
|
20
|
-
throw new factory_1.factory.errors.Argument('expires', 'must be Date');
|
|
21
|
-
}
|
|
22
|
-
const savingTask = {
|
|
23
|
-
...params,
|
|
24
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
25
|
-
numberOfTried: 0,
|
|
26
|
-
executionResults: []
|
|
27
|
-
};
|
|
28
|
-
const result = await this.taskModel.insertMany(savingTask, { rawResult: true });
|
|
29
|
-
const id = result.insertedIds?.[0]?.toHexString();
|
|
30
|
-
if (typeof id !== 'string') {
|
|
31
|
-
throw new factory_1.factory.errors.Internal('task not saved');
|
|
32
|
-
}
|
|
33
|
-
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
34
|
-
id,
|
|
35
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
36
|
-
expires // emit expires(2025-03-31~)
|
|
37
|
-
}, next);
|
|
38
|
-
return { id };
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Readyのままで期限切れのタスクをExpiredに変更する
|
|
42
|
-
*/
|
|
43
|
-
async makeExpiredMany(params) {
|
|
44
|
-
const { expiresLt } = params;
|
|
45
|
-
if (!(expiresLt instanceof Date)) {
|
|
46
|
-
throw new factory_1.factory.errors.Argument('expiresLt', 'must be Date');
|
|
47
|
-
}
|
|
48
|
-
return this.taskModel.updateMany({
|
|
49
|
-
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
50
|
-
expires: { $exists: true, $lt: expiresLt }
|
|
51
|
-
}, {
|
|
52
|
-
$set: {
|
|
53
|
-
status: factory_1.factory.taskStatus.Expired
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
.exec();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.AsyncActionLegacyRepo = AsyncActionLegacyRepo;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Connection, UpdateWriteOpResult } from 'mongoose';
|
|
2
|
-
import { factory } from '../factory';
|
|
3
|
-
/**
|
|
4
|
-
* 旧予定タスクリポジトリ
|
|
5
|
-
*/
|
|
6
|
-
export declare class ScheduledTaskLegacyRepo {
|
|
7
|
-
private readonly taskModel;
|
|
8
|
-
constructor(connection: Connection);
|
|
9
|
-
/**
|
|
10
|
-
* $eq:0をAbortedにする(特定のタスクのみ)(これらは中止されてもhubへ通知しない)
|
|
11
|
-
*/
|
|
12
|
-
abortLegacyTasks(params: {
|
|
13
|
-
intervalInMinutes: number;
|
|
14
|
-
name: {
|
|
15
|
-
$in: factory.taskName[];
|
|
16
|
-
};
|
|
17
|
-
}): Promise<UpdateWriteOpResult>;
|
|
18
|
-
/**
|
|
19
|
-
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
|
|
20
|
-
*/
|
|
21
|
-
emitRunningIfExistsLegacy(params: {
|
|
22
|
-
/**
|
|
23
|
-
* 必ずタスク名指定で実行する
|
|
24
|
-
*/
|
|
25
|
-
name: {
|
|
26
|
-
$eq: factory.taskName;
|
|
27
|
-
};
|
|
28
|
-
runsAt: {
|
|
29
|
-
$lt: Date;
|
|
30
|
-
};
|
|
31
|
-
sort: {
|
|
32
|
-
numberOfTried?: factory.sortType;
|
|
33
|
-
runsAt?: factory.sortType;
|
|
34
|
-
};
|
|
35
|
-
executor: {
|
|
36
|
-
name: string;
|
|
37
|
-
};
|
|
38
|
-
}): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
39
|
-
}
|
|
@@ -1,96 +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.ScheduledTaskLegacyRepo = void 0;
|
|
7
|
-
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
const task_1 = require("../eventEmitter/task");
|
|
9
|
-
const factory_1 = require("../factory");
|
|
10
|
-
const settings_1 = require("../settings");
|
|
11
|
-
const task_2 = require("./mongoose/schemas/task");
|
|
12
|
-
/**
|
|
13
|
-
* 旧予定タスクリポジトリ
|
|
14
|
-
*/
|
|
15
|
-
class ScheduledTaskLegacyRepo {
|
|
16
|
-
taskModel;
|
|
17
|
-
constructor(connection) {
|
|
18
|
-
this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* $eq:0をAbortedにする(特定のタスクのみ)(これらは中止されてもhubへ通知しない)
|
|
22
|
-
*/
|
|
23
|
-
async abortLegacyTasks(params) {
|
|
24
|
-
const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
|
|
25
|
-
.add(-params.intervalInMinutes, 'minutes')
|
|
26
|
-
.toDate();
|
|
27
|
-
return this.taskModel.updateMany({
|
|
28
|
-
status: { $eq: factory_1.factory.taskStatus.Running },
|
|
29
|
-
lastTriedAt: {
|
|
30
|
-
$type: 'date',
|
|
31
|
-
$lt: lastTriedAtShoudBeLessThan
|
|
32
|
-
},
|
|
33
|
-
remainingNumberOfTries: { $eq: 0 },
|
|
34
|
-
name: { $in: params.name.$in }
|
|
35
|
-
}, {
|
|
36
|
-
$set: {
|
|
37
|
-
status: factory_1.factory.taskStatus.Aborted,
|
|
38
|
-
dateAborted: new Date()
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
.exec();
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
|
|
45
|
-
*/
|
|
46
|
-
async emitRunningIfExistsLegacy(params
|
|
47
|
-
// next?: INextFunction // 現時点でタスク遅延実行ではnext指定なし(2026-07-30)
|
|
48
|
-
) {
|
|
49
|
-
if (!(params.runsAt.$lt instanceof Date)) {
|
|
50
|
-
throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
51
|
-
}
|
|
52
|
-
const projection = {
|
|
53
|
-
_id: 0,
|
|
54
|
-
id: { $toString: '$_id' },
|
|
55
|
-
name: 1
|
|
56
|
-
};
|
|
57
|
-
const nameEq = params.name?.$eq;
|
|
58
|
-
// インデックス'executeOneByNameIfExists'を想定したfilter
|
|
59
|
-
const filter = {
|
|
60
|
-
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
61
|
-
runsAt: { $lt: params.runsAt.$lt },
|
|
62
|
-
name: params.name
|
|
63
|
-
};
|
|
64
|
-
const doc = await this.taskModel.findOneAndUpdate(filter, {
|
|
65
|
-
$set: {
|
|
66
|
-
status: factory_1.factory.taskStatus.Running, // 実行中に変更
|
|
67
|
-
lastTriedAt: new Date(),
|
|
68
|
-
executor: params.executor
|
|
69
|
-
},
|
|
70
|
-
$inc: {
|
|
71
|
-
remainingNumberOfTries: -1, // 残りトライ可能回数減らす
|
|
72
|
-
numberOfTried: 1 // トライ回数増やす
|
|
73
|
-
}
|
|
74
|
-
}, {
|
|
75
|
-
new: true,
|
|
76
|
-
projection,
|
|
77
|
-
...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
|
|
78
|
-
? { sort: params.sort }
|
|
79
|
-
: undefined
|
|
80
|
-
})
|
|
81
|
-
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
82
|
-
.lean()
|
|
83
|
-
.exec();
|
|
84
|
-
if (doc === null) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
const changedTask = {
|
|
88
|
-
id: doc.id,
|
|
89
|
-
status: factory_1.factory.taskStatus.Running,
|
|
90
|
-
name: nameEq
|
|
91
|
-
};
|
|
92
|
-
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask);
|
|
93
|
-
return doc;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.ScheduledTaskLegacyRepo = ScheduledTaskLegacyRepo;
|