@chevre/domain 26.0.0-alpha.5 → 26.0.0-alpha.7
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/asyncActionLegacy.d.ts +23 -0
- package/lib/chevre/repo/asyncActionLegacy.js +59 -0
- package/lib/chevre/repo/scheduledTaskLegacy.d.ts +19 -0
- package/lib/chevre/repo/scheduledTaskLegacy.js +42 -0
- package/lib/chevre/repo/scheduledTaskMigration.d.ts +21 -0
- package/lib/chevre/repo/scheduledTaskMigration.js +70 -0
- package/lib/chevre/repo/task.d.ts +7 -27
- package/lib/chevre/repo/task.js +47 -69
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +12 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Connection, UpdateWriteOpResult } from 'mongoose';
|
|
2
|
+
import { factory } from '../factory';
|
|
3
|
+
import { IModel } from './mongoose/schemas/task';
|
|
4
|
+
/**
|
|
5
|
+
* 旧予定タスクリポジトリ
|
|
6
|
+
*/
|
|
7
|
+
export declare class ScheduledTaskLegacyRepo {
|
|
8
|
+
readonly taskModel: IModel;
|
|
9
|
+
constructor(connection: Connection);
|
|
10
|
+
/**
|
|
11
|
+
* $eq:0をAbortedにする(特定のタスクのみ)(これらは中止されてもhubへ通知しない)
|
|
12
|
+
*/
|
|
13
|
+
abortLegacyTasks(params: {
|
|
14
|
+
intervalInMinutes: number;
|
|
15
|
+
name: {
|
|
16
|
+
$in: factory.taskName[];
|
|
17
|
+
};
|
|
18
|
+
}): Promise<UpdateWriteOpResult>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 factory_1 = require("../factory");
|
|
9
|
+
const task_1 = require("./mongoose/schemas/task");
|
|
10
|
+
/**
|
|
11
|
+
* 旧予定タスクリポジトリ
|
|
12
|
+
*/
|
|
13
|
+
class ScheduledTaskLegacyRepo {
|
|
14
|
+
taskModel;
|
|
15
|
+
constructor(connection) {
|
|
16
|
+
this.taskModel = connection.model(task_1.modelName, (0, task_1.createSchema)());
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* $eq:0をAbortedにする(特定のタスクのみ)(これらは中止されてもhubへ通知しない)
|
|
20
|
+
*/
|
|
21
|
+
async abortLegacyTasks(params) {
|
|
22
|
+
const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
|
|
23
|
+
.add(-params.intervalInMinutes, 'minutes')
|
|
24
|
+
.toDate();
|
|
25
|
+
return this.taskModel.updateMany({
|
|
26
|
+
status: { $eq: factory_1.factory.taskStatus.Running },
|
|
27
|
+
lastTriedAt: {
|
|
28
|
+
$type: 'date',
|
|
29
|
+
$lt: lastTriedAtShoudBeLessThan
|
|
30
|
+
},
|
|
31
|
+
remainingNumberOfTries: { $eq: 0 },
|
|
32
|
+
name: { $in: params.name.$in }
|
|
33
|
+
}, {
|
|
34
|
+
$set: {
|
|
35
|
+
status: factory_1.factory.taskStatus.Aborted,
|
|
36
|
+
dateAborted: new Date()
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
.exec();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.ScheduledTaskLegacyRepo = ScheduledTaskLegacyRepo;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
}
|
|
70
|
+
exports.ScheduledTaskMigrationRepo = ScheduledTaskMigrationRepo;
|
|
@@ -16,13 +16,6 @@ type ICreatingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | '
|
|
|
16
16
|
export declare class TaskRepo {
|
|
17
17
|
readonly taskModel: IModel;
|
|
18
18
|
constructor(connection: Connection);
|
|
19
|
-
runImmediately(params: Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'name' | 'project' | 'remainingNumberOfTries' | 'runsAt'> & {
|
|
20
|
-
alternateName?: never;
|
|
21
|
-
identifier?: never;
|
|
22
|
-
expires: Date;
|
|
23
|
-
}, next: INextFunction): Promise<{
|
|
24
|
-
id: string;
|
|
25
|
-
}>;
|
|
26
19
|
saveMany(taskAttributes: ICreatingTask[]): Promise<{
|
|
27
20
|
id: string;
|
|
28
21
|
}[]>;
|
|
@@ -42,8 +35,9 @@ export declare class TaskRepo {
|
|
|
42
35
|
/**
|
|
43
36
|
* タスク識別子から冪等作成する
|
|
44
37
|
* reimplement createIfNotExistByIdentifier(2025-03-28~)
|
|
38
|
+
* reimplement runTaskByIdentifier(2026-08-03~)
|
|
45
39
|
*/
|
|
46
|
-
|
|
40
|
+
runTaskByIdentifier(params: ICreatingTask & {
|
|
47
41
|
alternateName: string;
|
|
48
42
|
identifier: string;
|
|
49
43
|
expires?: never;
|
|
@@ -121,24 +115,16 @@ export declare class TaskRepo {
|
|
|
121
115
|
nameFilterBeforeRunsAt: boolean;
|
|
122
116
|
}): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
123
117
|
/**
|
|
124
|
-
* Ready
|
|
118
|
+
* Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
|
|
125
119
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
retryTasks(params: {
|
|
121
|
+
intervalInMinutes: number;
|
|
128
122
|
}): Promise<UpdateWriteOpResult>;
|
|
129
123
|
/**
|
|
130
|
-
*
|
|
124
|
+
* $lte:0をReadyにする(特定のタスクを除いて) -> Readyにすれば自動的にAbortedになる
|
|
131
125
|
*/
|
|
132
|
-
|
|
126
|
+
retryAbortingTasksByName(params: {
|
|
133
127
|
intervalInMinutes: number;
|
|
134
|
-
/**
|
|
135
|
-
* リトライ条件に残り試行回数条件を追加する
|
|
136
|
-
* 十分に小さい数値を指定すれば、実質残り試行回数に関係なくRunningがReadyに変更されることになる
|
|
137
|
-
*/
|
|
138
|
-
remainingNumberOfTries: {
|
|
139
|
-
$gte?: number;
|
|
140
|
-
$lte?: number;
|
|
141
|
-
};
|
|
142
128
|
name: {
|
|
143
129
|
$in?: factory.taskName[];
|
|
144
130
|
};
|
|
@@ -151,12 +137,6 @@ export declare class TaskRepo {
|
|
|
151
137
|
id: string;
|
|
152
138
|
remainingNumberOfTries: number;
|
|
153
139
|
}): Promise<UpdateWriteOpResult>;
|
|
154
|
-
abortMany(params: {
|
|
155
|
-
intervalInMinutes: number;
|
|
156
|
-
name: {
|
|
157
|
-
$in?: factory.taskName[];
|
|
158
|
-
};
|
|
159
|
-
}): Promise<UpdateWriteOpResult>;
|
|
160
140
|
/**
|
|
161
141
|
* タスクIDから実行結果とステータスを保管する
|
|
162
142
|
* Abortedの場合、dateAbortedもセットする
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -48,31 +48,6 @@ class TaskRepo {
|
|
|
48
48
|
constructor(connection) {
|
|
49
49
|
this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
|
|
50
50
|
}
|
|
51
|
-
async runImmediately(params,
|
|
52
|
-
// support customr function(2025-05-25~)
|
|
53
|
-
next) {
|
|
54
|
-
const { expires } = params;
|
|
55
|
-
if (!(expires instanceof Date)) {
|
|
56
|
-
throw new factory_1.factory.errors.Argument('expires', 'must be Date');
|
|
57
|
-
}
|
|
58
|
-
const savingTask = {
|
|
59
|
-
...params,
|
|
60
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
61
|
-
numberOfTried: 0,
|
|
62
|
-
executionResults: []
|
|
63
|
-
};
|
|
64
|
-
const result = await this.taskModel.insertMany(savingTask, { rawResult: true });
|
|
65
|
-
const id = result.insertedIds?.[0]?.toHexString();
|
|
66
|
-
if (typeof id !== 'string') {
|
|
67
|
-
throw new factory_1.factory.errors.Internal('task not saved');
|
|
68
|
-
}
|
|
69
|
-
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
70
|
-
id,
|
|
71
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
72
|
-
expires // emit expires(2025-03-31~)
|
|
73
|
-
}, next);
|
|
74
|
-
return { id };
|
|
75
|
-
}
|
|
76
51
|
async saveMany(taskAttributes) {
|
|
77
52
|
const emitImmediately = true; // always true(2026-07-30~)
|
|
78
53
|
// const emitImmediately = options?.emitImmediately === true;
|
|
@@ -132,17 +107,24 @@ class TaskRepo {
|
|
|
132
107
|
/**
|
|
133
108
|
* タスク識別子から冪等作成する
|
|
134
109
|
* reimplement createIfNotExistByIdentifier(2025-03-28~)
|
|
110
|
+
* reimplement runTaskByIdentifier(2026-08-03~)
|
|
135
111
|
*/
|
|
136
|
-
async
|
|
112
|
+
async runTaskByIdentifier(params) {
|
|
137
113
|
const emitImmediately = true; // always true(2026-07-30~)
|
|
114
|
+
if (typeof params.identifier !== 'string' || params.identifier.length === 0) {
|
|
115
|
+
throw new factory_1.factory.errors.ArgumentNull('identifier');
|
|
116
|
+
}
|
|
138
117
|
if (typeof params.alternateName !== 'string' || params.alternateName.length === 0) {
|
|
139
118
|
throw new factory_1.factory.errors.ArgumentNull('alternateName');
|
|
140
119
|
}
|
|
120
|
+
if (params.identifier !== params.alternateName) {
|
|
121
|
+
throw new factory_1.factory.errors.Argument('identifier,alternateName not matched');
|
|
122
|
+
}
|
|
141
123
|
let createdTask;
|
|
142
124
|
const filterQuery = {
|
|
143
125
|
'project.id': { $eq: params.project.id },
|
|
144
126
|
name: { $eq: params.name },
|
|
145
|
-
|
|
127
|
+
identifier: { $exists: true, $eq: params.identifier }
|
|
146
128
|
};
|
|
147
129
|
const projection = {
|
|
148
130
|
_id: 0,
|
|
@@ -160,7 +142,7 @@ class TaskRepo {
|
|
|
160
142
|
catch (error) {
|
|
161
143
|
let throwsError = true;
|
|
162
144
|
if (await (0, errorHandler_1.isMongoDuplicateError)(error)) {
|
|
163
|
-
// すでに
|
|
145
|
+
// すでにidentifierが存在する場合ok
|
|
164
146
|
throwsError = false;
|
|
165
147
|
createdTask = await this.taskModel.findOne(filterQuery, projection)
|
|
166
148
|
.lean()
|
|
@@ -180,7 +162,7 @@ class TaskRepo {
|
|
|
180
162
|
}
|
|
181
163
|
}
|
|
182
164
|
else {
|
|
183
|
-
throw new factory_1.factory.errors.Internal(`falied in creating a task unexpectedly. ${params.
|
|
165
|
+
throw new factory_1.factory.errors.Internal(`falied in creating a task unexpectedly. ${params.identifier}`);
|
|
184
166
|
}
|
|
185
167
|
}
|
|
186
168
|
// /**
|
|
@@ -423,32 +405,47 @@ class TaskRepo {
|
|
|
423
405
|
return doc;
|
|
424
406
|
}
|
|
425
407
|
/**
|
|
426
|
-
* Ready
|
|
408
|
+
* Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
|
|
427
409
|
*/
|
|
428
|
-
async
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
410
|
+
async retryTasks(params) {
|
|
411
|
+
const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
|
|
412
|
+
.add(-params.intervalInMinutes, 'minutes')
|
|
413
|
+
.toDate();
|
|
414
|
+
// const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
|
|
415
|
+
// const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
|
|
416
|
+
return this.taskModel.updateMany(
|
|
417
|
+
// name: 'retry'のindexと連動しているので、条件の順序などには注意すること
|
|
418
|
+
// @see schemas/task
|
|
419
|
+
{
|
|
420
|
+
status: { $eq: factory_1.factory.taskStatus.Running },
|
|
421
|
+
lastTriedAt: {
|
|
422
|
+
$type: 'date',
|
|
423
|
+
$lt: lastTriedAtShoudBeLessThan
|
|
424
|
+
},
|
|
425
|
+
remainingNumberOfTries: { $gte: 1 },
|
|
426
|
+
// ...(typeof remainingNumberOfTriesGte === 'number')
|
|
427
|
+
// ? { remainingNumberOfTries: { $gte: remainingNumberOfTriesGte } }
|
|
428
|
+
// : undefined,
|
|
429
|
+
// ...(typeof remainingNumberOfTriesLte === 'number')
|
|
430
|
+
// ? { remainingNumberOfTries: { $lte: remainingNumberOfTriesLte } }
|
|
431
|
+
// : undefined,
|
|
432
|
+
// ...(Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined
|
|
436
433
|
}, {
|
|
437
434
|
$set: {
|
|
438
|
-
status: factory_1.factory.taskStatus.
|
|
435
|
+
status: factory_1.factory.taskStatus.Ready // 実行前に変更
|
|
439
436
|
}
|
|
440
437
|
})
|
|
441
438
|
.exec();
|
|
442
439
|
}
|
|
443
440
|
/**
|
|
444
|
-
*
|
|
441
|
+
* $lte:0をReadyにする(特定のタスクを除いて) -> Readyにすれば自動的にAbortedになる
|
|
445
442
|
*/
|
|
446
|
-
async
|
|
443
|
+
async retryAbortingTasksByName(params) {
|
|
447
444
|
const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
|
|
448
445
|
.add(-params.intervalInMinutes, 'minutes')
|
|
449
446
|
.toDate();
|
|
450
|
-
const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
|
|
451
|
-
const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
|
|
447
|
+
// const remainingNumberOfTriesGte = params.remainingNumberOfTries.$gte;
|
|
448
|
+
// const remainingNumberOfTriesLte = params.remainingNumberOfTries.$lte;
|
|
452
449
|
return this.taskModel.updateMany(
|
|
453
450
|
// name: 'retry'のindexと連動しているので、条件の順序などには注意すること
|
|
454
451
|
// @see schemas/task
|
|
@@ -458,12 +455,13 @@ class TaskRepo {
|
|
|
458
455
|
$type: 'date',
|
|
459
456
|
$lt: lastTriedAtShoudBeLessThan
|
|
460
457
|
},
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
458
|
+
remainingNumberOfTries: { $lte: 0 },
|
|
459
|
+
// ...(typeof remainingNumberOfTriesGte === 'number')
|
|
460
|
+
// ? { remainingNumberOfTries: { $gte: remainingNumberOfTriesGte } }
|
|
461
|
+
// : undefined,
|
|
462
|
+
// ...(typeof remainingNumberOfTriesLte === 'number')
|
|
463
|
+
// ? { remainingNumberOfTries: { $lte: remainingNumberOfTriesLte } }
|
|
464
|
+
// : undefined,
|
|
467
465
|
...(Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined
|
|
468
466
|
}, {
|
|
469
467
|
$set: {
|
|
@@ -490,26 +488,6 @@ class TaskRepo {
|
|
|
490
488
|
})
|
|
491
489
|
.exec();
|
|
492
490
|
}
|
|
493
|
-
async abortMany(params) {
|
|
494
|
-
const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
|
|
495
|
-
.add(-params.intervalInMinutes, 'minutes')
|
|
496
|
-
.toDate();
|
|
497
|
-
return this.taskModel.updateMany({
|
|
498
|
-
status: { $eq: factory_1.factory.taskStatus.Running },
|
|
499
|
-
lastTriedAt: {
|
|
500
|
-
$type: 'date',
|
|
501
|
-
$lt: lastTriedAtShoudBeLessThan
|
|
502
|
-
},
|
|
503
|
-
remainingNumberOfTries: { $eq: 0 },
|
|
504
|
-
...(Array.isArray(params.name.$in)) ? { name: { $in: params.name.$in } } : undefined
|
|
505
|
-
}, {
|
|
506
|
-
$set: {
|
|
507
|
-
status: factory_1.factory.taskStatus.Aborted,
|
|
508
|
-
dateAborted: new Date()
|
|
509
|
-
}
|
|
510
|
-
})
|
|
511
|
-
.exec();
|
|
512
|
-
}
|
|
513
491
|
/**
|
|
514
492
|
* タスクIDから実行結果とステータスを保管する
|
|
515
493
|
* Abortedの場合、dateAbortedもセットする
|
|
@@ -16,6 +16,7 @@ import type { CheckThingActionRepo } from './repo/action/checkThing';
|
|
|
16
16
|
import type { PayActionRepo } from './repo/action/pay';
|
|
17
17
|
import type { RefundActionRepo } from './repo/action/refund';
|
|
18
18
|
import type { AsyncActionRepo } from './repo/asyncAction';
|
|
19
|
+
import type { AsyncActionLegacyRepo } from './repo/asyncActionLegacy';
|
|
19
20
|
import type { AdditionalPropertyRepo } from './repo/additionalProperty';
|
|
20
21
|
import type { AdminAsyncActionRepo } from './repo/adminAsyncAction';
|
|
21
22
|
import type { AdminScheduledTaskRepo } from './repo/adminScheduledTask';
|
|
@@ -505,6 +506,10 @@ export type AsyncAction = AsyncActionRepo;
|
|
|
505
506
|
export declare namespace AsyncAction {
|
|
506
507
|
function createInstance(...params: ConstructorParameters<typeof AsyncActionRepo>): Promise<AsyncActionRepo>;
|
|
507
508
|
}
|
|
509
|
+
export type AsyncActionLegacy = AsyncActionLegacyRepo;
|
|
510
|
+
export declare namespace AsyncActionLegacy {
|
|
511
|
+
function createInstance(...params: ConstructorParameters<typeof AsyncActionLegacyRepo>): Promise<AsyncActionLegacyRepo>;
|
|
512
|
+
}
|
|
508
513
|
export type Ticket = TicketRepo;
|
|
509
514
|
export declare namespace Ticket {
|
|
510
515
|
function createInstance(...params: ConstructorParameters<typeof TicketRepo>): Promise<TicketRepo>;
|
package/lib/chevre/repository.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.MovieTicketType = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.EventOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Authorization = exports.CategoryCode = exports.assetTransaction = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AggregateTask = exports.AggregateScheduledTask = exports.AggregateAction = exports.AdminTask = exports.AdminScheduledTask = exports.AdminAsyncAction = exports.AdditionalProperty = exports.action = exports.Action = exports.AccountTitle = exports.AccountingReport = exports.AcceptedOffer = void 0;
|
|
4
|
-
exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.AsyncAction = exports.Task = exports.ScheduledTask = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = exports.Person = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = void 0;
|
|
4
|
+
exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.AsyncActionLegacy = exports.AsyncAction = exports.Task = exports.ScheduledTask = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = exports.Person = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = void 0;
|
|
5
5
|
var AcceptedOffer;
|
|
6
6
|
(function (AcceptedOffer) {
|
|
7
7
|
let repo;
|
|
@@ -1066,6 +1066,17 @@ var AsyncAction;
|
|
|
1066
1066
|
}
|
|
1067
1067
|
AsyncAction.createInstance = createInstance;
|
|
1068
1068
|
})(AsyncAction || (exports.AsyncAction = AsyncAction = {}));
|
|
1069
|
+
var AsyncActionLegacy;
|
|
1070
|
+
(function (AsyncActionLegacy) {
|
|
1071
|
+
let repo;
|
|
1072
|
+
async function createInstance(...params) {
|
|
1073
|
+
if (repo === undefined) {
|
|
1074
|
+
repo = (await import('./repo/asyncActionLegacy.js')).AsyncActionLegacyRepo;
|
|
1075
|
+
}
|
|
1076
|
+
return new repo(...params);
|
|
1077
|
+
}
|
|
1078
|
+
AsyncActionLegacy.createInstance = createInstance;
|
|
1079
|
+
})(AsyncActionLegacy || (exports.AsyncActionLegacy = AsyncActionLegacy = {}));
|
|
1069
1080
|
var Ticket;
|
|
1070
1081
|
(function (Ticket) {
|
|
1071
1082
|
let repo;
|
|
@@ -75,7 +75,7 @@ function createSendOrderTaskIfNotExist(params) {
|
|
|
75
75
|
};
|
|
76
76
|
debug('processing createSendOrderTaskIfNotExist...', sendOrderTask);
|
|
77
77
|
// await repos.task.createSendOrderTaskIfNotExist(sendOrderTask);
|
|
78
|
-
await repos.task.
|
|
78
|
+
await repos.task.runTaskByIdentifier(sendOrderTask);
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
function createOnAuthorizationCreatedTask(order) {
|
|
@@ -107,7 +107,7 @@ function createOnAuthorizationCreatedTask(order) {
|
|
|
107
107
|
},
|
|
108
108
|
project: { id: order.project.id, typeOf: factory_1.factory.organizationType.Project }
|
|
109
109
|
};
|
|
110
|
-
await repos.task.
|
|
110
|
+
await repos.task.runTaskByIdentifier(task);
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
}
|
|
@@ -64,7 +64,7 @@ function createConfirmPayTransactionTasks(order, simpleOrder) {
|
|
|
64
64
|
executionResults: [],
|
|
65
65
|
data
|
|
66
66
|
};
|
|
67
|
-
await repos.task.
|
|
67
|
+
await repos.task.runTaskByIdentifier(confirmPayTransactionTask);
|
|
68
68
|
// 冗長なタスク作成を回避
|
|
69
69
|
// const existingTasks = await repos.task.projectFields(
|
|
70
70
|
// {
|
|
@@ -59,7 +59,7 @@ function createSendEmailMessageTaskIfNotExist(params) {
|
|
|
59
59
|
executionResults: [],
|
|
60
60
|
data: { actionAttributes }
|
|
61
61
|
};
|
|
62
|
-
await repos.task.
|
|
62
|
+
await repos.task.runTaskByIdentifier(sendEmailMessageTask);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
}
|
|
@@ -61,7 +61,7 @@ function createConfirmReserveTransactionTasksIfNotExist(order, simpleOrder, opti
|
|
|
61
61
|
executionResults: [],
|
|
62
62
|
data
|
|
63
63
|
};
|
|
64
|
-
await repos.task.
|
|
64
|
+
await repos.task.runTaskByIdentifier(confirmReserveTransactionTask);
|
|
65
65
|
if (options.force === true) {
|
|
66
66
|
const existingTask = await repos.task.findByIdentifier({
|
|
67
67
|
identifier: taskIdentifier,
|
|
@@ -37,7 +37,7 @@ function onOrderProcessing(params) {
|
|
|
37
37
|
await repos.task.saveMany(tasks);
|
|
38
38
|
// uniqueness of CheckResource task(2025-03-29~)
|
|
39
39
|
if (creatingCheckResourceTask !== undefined) {
|
|
40
|
-
await repos.task.
|
|
40
|
+
await repos.task.runTaskByIdentifier(creatingCheckResourceTask);
|
|
41
41
|
}
|
|
42
42
|
switch (params.order.orderStatus) {
|
|
43
43
|
case factory_1.factory.orderStatus.OrderProcessing:
|
|
@@ -137,7 +137,7 @@ function onReservationConfirmed(confirmedReservations, reserveAction) {
|
|
|
137
137
|
await repos.task.saveMany(taskAttributes);
|
|
138
138
|
}
|
|
139
139
|
if (onAuthorizationCreatedTask !== undefined) {
|
|
140
|
-
await repos.task.
|
|
140
|
+
await repos.task.runTaskByIdentifier(onAuthorizationCreatedTask);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
};
|
package/package.json
CHANGED