@chevre/domain 26.0.0-alpha.13 → 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 +12 -0
- package/lib/chevre/repo/adminTask.js +24 -0
- package/lib/chevre/repo/mongoose/schemas/task.js +4 -0
- package/lib/chevre/repo/task.d.ts +1 -71
- package/lib/chevre/repo/task.js +8 -186
- 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 +3 -3
- package/lib/chevre/service/task.js +3 -3
- 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/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
|
@@ -16,6 +16,18 @@ export declare class AdminTaskRepo {
|
|
|
16
16
|
* 検索する
|
|
17
17
|
*/
|
|
18
18
|
findTasks(params: factory.task.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.task.ITask<factory.taskName>[]>;
|
|
19
|
+
/**
|
|
20
|
+
* cron:notifyLatency専用
|
|
21
|
+
*/
|
|
22
|
+
countDelayedTasks(params: {
|
|
23
|
+
delayInSeconds: number;
|
|
24
|
+
name: {
|
|
25
|
+
$nin?: factory.taskName[];
|
|
26
|
+
};
|
|
27
|
+
limit?: number;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
count: number;
|
|
30
|
+
}>;
|
|
19
31
|
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, {}> & Omit<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, "id"> & {
|
|
20
32
|
expires?: never;
|
|
21
33
|
} & {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.AdminTaskRepo = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
4
8
|
const factory_1 = require("../factory");
|
|
5
9
|
const settings_1 = require("../settings");
|
|
6
10
|
const task_1 = require("./mongoose/schemas/task");
|
|
@@ -151,6 +155,26 @@ class AdminTaskRepo {
|
|
|
151
155
|
.lean() // lean(2024-09-26~)
|
|
152
156
|
.exec();
|
|
153
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* cron:notifyLatency専用
|
|
160
|
+
*/
|
|
161
|
+
async countDelayedTasks(params) {
|
|
162
|
+
const { limit } = params;
|
|
163
|
+
const runsAtLt = (0, moment_1.default)()
|
|
164
|
+
.add(-params.delayInSeconds, 'seconds')
|
|
165
|
+
.toDate();
|
|
166
|
+
const query = this.taskModel.countDocuments({
|
|
167
|
+
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
168
|
+
runsAt: { $lt: runsAtLt },
|
|
169
|
+
...(Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined
|
|
170
|
+
});
|
|
171
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
172
|
+
query.limit(limit);
|
|
173
|
+
}
|
|
174
|
+
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
175
|
+
.exec();
|
|
176
|
+
return { count };
|
|
177
|
+
}
|
|
154
178
|
getCursor(conditions, projection) {
|
|
155
179
|
return this.taskModel.find(conditions, projection)
|
|
156
180
|
.sort({ runsAt: factory_1.factory.sortType.Ascending })
|
|
@@ -178,6 +178,10 @@ const indexes = [
|
|
|
178
178
|
{ status: 1, runsAt: 1, name: 1 },
|
|
179
179
|
{ name: 'executeOneByNameIfExists' } // add(2025-03-08~)
|
|
180
180
|
],
|
|
181
|
+
[
|
|
182
|
+
{ status: 1, name: 1, runsAt: 1 },
|
|
183
|
+
{ name: 'runDelayedTaskByName' } // add(2026-08-05~)
|
|
184
|
+
],
|
|
181
185
|
[
|
|
182
186
|
{ status: 1, remainingNumberOfTries: 1, lastTriedAt: 1 },
|
|
183
187
|
{
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Connection, UpdateWriteOpResult } from 'mongoose';
|
|
2
|
-
import { INextFunction } from '../eventEmitter/task';
|
|
3
2
|
import { factory } from '../factory';
|
|
4
3
|
import { IDocType } from './mongoose/schemas/task';
|
|
5
4
|
import type { IExecutableTask } from '../taskSettings';
|
|
@@ -71,64 +70,6 @@ export declare class TaskRepo {
|
|
|
71
70
|
};
|
|
72
71
|
expires?: never;
|
|
73
72
|
}): Promise<IExecutableTask<factory.taskName> | null>;
|
|
74
|
-
/**
|
|
75
|
-
* 潜在的に実行されるべきタスクをカウントする
|
|
76
|
-
* add(2025-03-16~)
|
|
77
|
-
*/
|
|
78
|
-
countPotentiallyRunning(params: {
|
|
79
|
-
name?: {
|
|
80
|
-
$eq?: factory.taskName;
|
|
81
|
-
$in?: factory.taskName[];
|
|
82
|
-
};
|
|
83
|
-
runsAt: {
|
|
84
|
-
$lt: Date;
|
|
85
|
-
};
|
|
86
|
-
limit: number;
|
|
87
|
-
}): Promise<{
|
|
88
|
-
count: number;
|
|
89
|
-
}>;
|
|
90
|
-
/**
|
|
91
|
-
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更する
|
|
92
|
-
*/
|
|
93
|
-
private runDelayedTask;
|
|
94
|
-
/**
|
|
95
|
-
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
|
|
96
|
-
*/
|
|
97
|
-
emitRunningIfExistsByName(params: {
|
|
98
|
-
/**
|
|
99
|
-
* 必ずタスク名指定で実行する
|
|
100
|
-
*/
|
|
101
|
-
name: {
|
|
102
|
-
$eq: factory.taskName;
|
|
103
|
-
$in?: never;
|
|
104
|
-
} | {
|
|
105
|
-
$eq?: never;
|
|
106
|
-
$in: factory.taskName[];
|
|
107
|
-
};
|
|
108
|
-
runsAt: {
|
|
109
|
-
$lt: Date;
|
|
110
|
-
};
|
|
111
|
-
sort: {
|
|
112
|
-
numberOfTried?: factory.sortType;
|
|
113
|
-
runsAt?: factory.sortType;
|
|
114
|
-
};
|
|
115
|
-
executor: {
|
|
116
|
-
name: string;
|
|
117
|
-
};
|
|
118
|
-
}): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
119
|
-
/**
|
|
120
|
-
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
|
|
121
|
-
* taskNameで絞らない
|
|
122
|
-
* 2026-08-04~
|
|
123
|
-
*/
|
|
124
|
-
emitRunningIfExistsNoName(params: {
|
|
125
|
-
runsAt: {
|
|
126
|
-
$lt: Date;
|
|
127
|
-
};
|
|
128
|
-
executor: {
|
|
129
|
-
name: string;
|
|
130
|
-
};
|
|
131
|
-
}): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
132
73
|
/**
|
|
133
74
|
* Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
|
|
134
75
|
*/
|
|
@@ -167,12 +108,10 @@ export declare class TaskRepo {
|
|
|
167
108
|
* タスクID
|
|
168
109
|
*/
|
|
169
110
|
id: string;
|
|
170
|
-
remainingNumberOfTries: number;
|
|
171
|
-
name: factory.taskName;
|
|
172
111
|
}, update: {
|
|
173
112
|
status: factory.taskStatus.Executed | factory.taskStatus.Running | factory.taskStatus.Aborted;
|
|
174
113
|
executionResult: factory.task.IExecutionResult;
|
|
175
|
-
}
|
|
114
|
+
}): Promise<void>;
|
|
176
115
|
deleteByProject(params: {
|
|
177
116
|
project: {
|
|
178
117
|
id: string;
|
|
@@ -186,14 +125,5 @@ export declare class TaskRepo {
|
|
|
186
125
|
$lt: Date;
|
|
187
126
|
};
|
|
188
127
|
}): Promise<import("mongodb").DeleteResult>;
|
|
189
|
-
countDelayedTasks(params: {
|
|
190
|
-
delayInSeconds: number;
|
|
191
|
-
name: {
|
|
192
|
-
$nin?: factory.taskName[];
|
|
193
|
-
};
|
|
194
|
-
limit?: number;
|
|
195
|
-
}): Promise<{
|
|
196
|
-
count: number;
|
|
197
|
-
}>;
|
|
198
128
|
}
|
|
199
129
|
export {};
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -324,166 +324,6 @@ class TaskRepo {
|
|
|
324
324
|
// }
|
|
325
325
|
// return doc;
|
|
326
326
|
// }
|
|
327
|
-
/**
|
|
328
|
-
* 潜在的に実行されるべきタスクをカウントする
|
|
329
|
-
* add(2025-03-16~)
|
|
330
|
-
*/
|
|
331
|
-
async countPotentiallyRunning(params) {
|
|
332
|
-
const { runsAt, limit, name } = params;
|
|
333
|
-
const nameEq = name?.$eq;
|
|
334
|
-
const nameIn = name?.$in;
|
|
335
|
-
if (!(runsAt.$lt instanceof Date)) {
|
|
336
|
-
throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
337
|
-
}
|
|
338
|
-
const query = this.taskModel.countDocuments({
|
|
339
|
-
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
340
|
-
runsAt: { $lt: params.runsAt.$lt },
|
|
341
|
-
...(typeof nameEq === 'string' || Array.isArray(nameIn))
|
|
342
|
-
? {
|
|
343
|
-
name: {
|
|
344
|
-
...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined,
|
|
345
|
-
...(Array.isArray(nameIn)) ? { $in: nameIn } : undefined
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
: undefined
|
|
349
|
-
});
|
|
350
|
-
if (typeof limit === 'number' && limit >= 0) {
|
|
351
|
-
query.limit(limit);
|
|
352
|
-
}
|
|
353
|
-
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
354
|
-
.exec();
|
|
355
|
-
return { count };
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更する
|
|
359
|
-
*/
|
|
360
|
-
async runDelayedTask(params) {
|
|
361
|
-
const { filter } = params;
|
|
362
|
-
const projection = {
|
|
363
|
-
_id: 0,
|
|
364
|
-
id: { $toString: '$_id' },
|
|
365
|
-
name: 1
|
|
366
|
-
};
|
|
367
|
-
return this.taskModel.findOneAndUpdate(filter, {
|
|
368
|
-
$set: {
|
|
369
|
-
status: factory_1.factory.taskStatus.Running, // 実行中に変更
|
|
370
|
-
lastTriedAt: new Date(),
|
|
371
|
-
executor: params.executor
|
|
372
|
-
},
|
|
373
|
-
$inc: {
|
|
374
|
-
remainingNumberOfTries: -1, // 残りトライ可能回数減らす
|
|
375
|
-
numberOfTried: 1 // トライ回数増やす
|
|
376
|
-
}
|
|
377
|
-
}, {
|
|
378
|
-
new: true,
|
|
379
|
-
projection,
|
|
380
|
-
...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
|
|
381
|
-
? { sort: params.sort }
|
|
382
|
-
: undefined
|
|
383
|
-
})
|
|
384
|
-
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
385
|
-
.lean()
|
|
386
|
-
.exec();
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
|
|
390
|
-
*/
|
|
391
|
-
async emitRunningIfExistsByName(params) {
|
|
392
|
-
if (!(params.runsAt.$lt instanceof Date)) {
|
|
393
|
-
throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
394
|
-
}
|
|
395
|
-
// const projection: ProjectionType<IDocType> = {
|
|
396
|
-
// _id: 0,
|
|
397
|
-
// id: { $toString: '$_id' },
|
|
398
|
-
// name: 1
|
|
399
|
-
// };
|
|
400
|
-
// インデックス'executeOneByNameIfExists'を想定したfilter
|
|
401
|
-
const filter = {
|
|
402
|
-
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
403
|
-
runsAt: { $lt: params.runsAt.$lt },
|
|
404
|
-
name: params.name
|
|
405
|
-
};
|
|
406
|
-
const doc = await this.runDelayedTask({
|
|
407
|
-
filter,
|
|
408
|
-
sort: params.sort,
|
|
409
|
-
executor: params.executor
|
|
410
|
-
});
|
|
411
|
-
// const doc = await this.taskModel.findOneAndUpdate(
|
|
412
|
-
// filter,
|
|
413
|
-
// {
|
|
414
|
-
// $set: {
|
|
415
|
-
// status: factory.taskStatus.Running, // 実行中に変更
|
|
416
|
-
// lastTriedAt: new Date(),
|
|
417
|
-
// executor: params.executor
|
|
418
|
-
// },
|
|
419
|
-
// $inc: {
|
|
420
|
-
// remainingNumberOfTries: -1, // 残りトライ可能回数減らす
|
|
421
|
-
// numberOfTried: 1 // トライ回数増やす
|
|
422
|
-
// }
|
|
423
|
-
// },
|
|
424
|
-
// {
|
|
425
|
-
// new: true,
|
|
426
|
-
// projection,
|
|
427
|
-
// ...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
|
|
428
|
-
// ? { sort: params.sort }
|
|
429
|
-
// : undefined
|
|
430
|
-
// }
|
|
431
|
-
// )
|
|
432
|
-
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
433
|
-
// .lean<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'>>()
|
|
434
|
-
// .exec();
|
|
435
|
-
if (doc === null) {
|
|
436
|
-
return null;
|
|
437
|
-
}
|
|
438
|
-
const nameEq = params.name?.$eq;
|
|
439
|
-
let changedTask;
|
|
440
|
-
if (typeof nameEq === 'string') {
|
|
441
|
-
changedTask = {
|
|
442
|
-
id: doc.id,
|
|
443
|
-
status: factory_1.factory.taskStatus.Running,
|
|
444
|
-
name: nameEq
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
else {
|
|
448
|
-
changedTask = {
|
|
449
|
-
id: doc.id,
|
|
450
|
-
status: factory_1.factory.taskStatus.Running
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask);
|
|
454
|
-
return doc;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
|
|
458
|
-
* taskNameで絞らない
|
|
459
|
-
* 2026-08-04~
|
|
460
|
-
*/
|
|
461
|
-
async emitRunningIfExistsNoName(params) {
|
|
462
|
-
if (!(params.runsAt.$lt instanceof Date)) {
|
|
463
|
-
throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
464
|
-
}
|
|
465
|
-
// インデックス'executeOneByNameIfExists'を想定したfilter
|
|
466
|
-
const filter = {
|
|
467
|
-
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
468
|
-
runsAt: { $lt: params.runsAt.$lt }
|
|
469
|
-
};
|
|
470
|
-
const doc = await this.runDelayedTask({
|
|
471
|
-
filter,
|
|
472
|
-
sort: {
|
|
473
|
-
runsAt: factory_1.factory.sortType.Ascending // ソートはrunsAtのみにしてみる(2026-08-04~)
|
|
474
|
-
},
|
|
475
|
-
executor: params.executor
|
|
476
|
-
});
|
|
477
|
-
if (doc === null) {
|
|
478
|
-
return null;
|
|
479
|
-
}
|
|
480
|
-
const changedTask = {
|
|
481
|
-
id: doc.id,
|
|
482
|
-
status: factory_1.factory.taskStatus.Running
|
|
483
|
-
};
|
|
484
|
-
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask);
|
|
485
|
-
return doc;
|
|
486
|
-
}
|
|
487
327
|
/**
|
|
488
328
|
* Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
|
|
489
329
|
*/
|
|
@@ -596,10 +436,8 @@ class TaskRepo {
|
|
|
596
436
|
* タスクIDから実行結果とステータスを保管する
|
|
597
437
|
* Abortedの場合、dateAbortedもセットする
|
|
598
438
|
*/
|
|
599
|
-
async setExecutionResultAndStatus(params, update
|
|
600
|
-
|
|
601
|
-
next) {
|
|
602
|
-
const { id, remainingNumberOfTries, name } = params;
|
|
439
|
+
async setExecutionResultAndStatus(params, update) {
|
|
440
|
+
const { id } = params;
|
|
603
441
|
const { status, executionResult } = update;
|
|
604
442
|
await this.taskModel.updateOne({ _id: { $eq: id } }, {
|
|
605
443
|
$set: {
|
|
@@ -609,11 +447,12 @@ class TaskRepo {
|
|
|
609
447
|
$push: { executionResults: executionResult }
|
|
610
448
|
})
|
|
611
449
|
.exec();
|
|
612
|
-
//
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
450
|
+
// discontinue next(2026-08-05~)
|
|
451
|
+
// // emit event(2025-05-26~)
|
|
452
|
+
// if (typeof next === 'function') {
|
|
453
|
+
// const changedTask: IExecutedTask = { id, name, status, remainingNumberOfTries, executionResult };
|
|
454
|
+
// taskEventEmitter.emitTaskStatusChanged(changedTask, next);
|
|
455
|
+
// }
|
|
617
456
|
}
|
|
618
457
|
// 非同期アクションへ移行したので不要(2026-08-04~)
|
|
619
458
|
// /**
|
|
@@ -677,22 +516,5 @@ class TaskRepo {
|
|
|
677
516
|
})
|
|
678
517
|
.exec();
|
|
679
518
|
}
|
|
680
|
-
async countDelayedTasks(params) {
|
|
681
|
-
const { limit } = params;
|
|
682
|
-
const runsAtLt = (0, moment_1.default)()
|
|
683
|
-
.add(-params.delayInSeconds, 'seconds')
|
|
684
|
-
.toDate();
|
|
685
|
-
const query = this.taskModel.countDocuments({
|
|
686
|
-
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
687
|
-
runsAt: { $lt: runsAtLt },
|
|
688
|
-
...(Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined
|
|
689
|
-
});
|
|
690
|
-
if (typeof limit === 'number' && limit >= 0) {
|
|
691
|
-
query.limit(limit);
|
|
692
|
-
}
|
|
693
|
-
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
694
|
-
.exec();
|
|
695
|
-
return { count };
|
|
696
|
-
}
|
|
697
519
|
}
|
|
698
520
|
exports.TaskRepo = TaskRepo;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
import { factory } from '../factory';
|
|
3
|
+
/**
|
|
4
|
+
* 遅延タスクリポジトリ
|
|
5
|
+
*/
|
|
6
|
+
export declare class TaskDelayedRepo {
|
|
7
|
+
private readonly taskModel;
|
|
8
|
+
constructor(connection: Connection);
|
|
9
|
+
/**
|
|
10
|
+
* 潜在的に実行されるべきタスクをカウントする
|
|
11
|
+
* add(2025-03-16~)
|
|
12
|
+
*/
|
|
13
|
+
countPotentiallyRunning(params: {
|
|
14
|
+
name?: {
|
|
15
|
+
$eq?: factory.taskName;
|
|
16
|
+
$in?: factory.taskName[];
|
|
17
|
+
};
|
|
18
|
+
runsAt: {
|
|
19
|
+
$lt: Date;
|
|
20
|
+
};
|
|
21
|
+
limit: number;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
count: number;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更する
|
|
27
|
+
*/
|
|
28
|
+
private runDelayedTask;
|
|
29
|
+
/**
|
|
30
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
|
|
31
|
+
*/
|
|
32
|
+
emitRunningIfExistsByName(params: {
|
|
33
|
+
/**
|
|
34
|
+
* 必ずタスク名指定で実行する
|
|
35
|
+
*/
|
|
36
|
+
name: {
|
|
37
|
+
$eq: factory.taskName;
|
|
38
|
+
$in?: never;
|
|
39
|
+
} | {
|
|
40
|
+
$eq?: never;
|
|
41
|
+
$in: factory.taskName[];
|
|
42
|
+
};
|
|
43
|
+
runsAt: {
|
|
44
|
+
$lt: Date;
|
|
45
|
+
};
|
|
46
|
+
sort: {
|
|
47
|
+
numberOfTried?: factory.sortType;
|
|
48
|
+
runsAt?: factory.sortType;
|
|
49
|
+
};
|
|
50
|
+
executor: {
|
|
51
|
+
name: string;
|
|
52
|
+
};
|
|
53
|
+
}): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
54
|
+
/**
|
|
55
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
|
|
56
|
+
* taskNameで絞らない
|
|
57
|
+
* 2026-08-04~
|
|
58
|
+
*/
|
|
59
|
+
emitRunningIfExistsNoName(params: {
|
|
60
|
+
runsAt: {
|
|
61
|
+
$lt: Date;
|
|
62
|
+
};
|
|
63
|
+
executor: {
|
|
64
|
+
name: string;
|
|
65
|
+
};
|
|
66
|
+
}): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskDelayedRepo = void 0;
|
|
4
|
+
const task_1 = require("../eventEmitter/task");
|
|
5
|
+
const factory_1 = require("../factory");
|
|
6
|
+
const settings_1 = require("../settings");
|
|
7
|
+
const task_2 = require("./mongoose/schemas/task");
|
|
8
|
+
/**
|
|
9
|
+
* 遅延タスクリポジトリ
|
|
10
|
+
*/
|
|
11
|
+
class TaskDelayedRepo {
|
|
12
|
+
taskModel;
|
|
13
|
+
constructor(connection) {
|
|
14
|
+
this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 潜在的に実行されるべきタスクをカウントする
|
|
18
|
+
* add(2025-03-16~)
|
|
19
|
+
*/
|
|
20
|
+
async countPotentiallyRunning(params) {
|
|
21
|
+
const { runsAt, limit, name } = params;
|
|
22
|
+
const nameEq = name?.$eq;
|
|
23
|
+
const nameIn = name?.$in;
|
|
24
|
+
if (!(runsAt.$lt instanceof Date)) {
|
|
25
|
+
throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
26
|
+
}
|
|
27
|
+
const query = this.taskModel.countDocuments({
|
|
28
|
+
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
29
|
+
...(typeof nameEq === 'string' || Array.isArray(nameIn))
|
|
30
|
+
? {
|
|
31
|
+
name: {
|
|
32
|
+
...(typeof nameEq === 'string') ? { $eq: nameEq } : undefined,
|
|
33
|
+
...(Array.isArray(nameIn)) ? { $in: nameIn } : undefined
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
: undefined,
|
|
37
|
+
runsAt: { $lt: params.runsAt.$lt }
|
|
38
|
+
});
|
|
39
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
40
|
+
query.limit(limit);
|
|
41
|
+
}
|
|
42
|
+
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
43
|
+
.exec();
|
|
44
|
+
return { count };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更する
|
|
48
|
+
*/
|
|
49
|
+
async runDelayedTask(params) {
|
|
50
|
+
const { filter } = params;
|
|
51
|
+
const projection = {
|
|
52
|
+
_id: 0,
|
|
53
|
+
id: { $toString: '$_id' },
|
|
54
|
+
name: 1
|
|
55
|
+
};
|
|
56
|
+
return this.taskModel.findOneAndUpdate(filter, {
|
|
57
|
+
$set: {
|
|
58
|
+
status: factory_1.factory.taskStatus.Running, // 実行中に変更
|
|
59
|
+
lastTriedAt: new Date(),
|
|
60
|
+
executor: params.executor
|
|
61
|
+
},
|
|
62
|
+
$inc: {
|
|
63
|
+
remainingNumberOfTries: -1, // 残りトライ可能回数減らす
|
|
64
|
+
numberOfTried: 1 // トライ回数増やす
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
new: true,
|
|
68
|
+
projection,
|
|
69
|
+
...(typeof params.sort.numberOfTried === 'number' || typeof params.sort.runsAt === 'number')
|
|
70
|
+
? { sort: params.sort }
|
|
71
|
+
: undefined
|
|
72
|
+
})
|
|
73
|
+
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
74
|
+
.lean()
|
|
75
|
+
.exec();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
|
|
79
|
+
*/
|
|
80
|
+
async emitRunningIfExistsByName(params) {
|
|
81
|
+
if (!(params.runsAt.$lt instanceof Date)) {
|
|
82
|
+
throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
83
|
+
}
|
|
84
|
+
// インデックス'executeOneByNameIfExists'を想定したfilter
|
|
85
|
+
const filter = {
|
|
86
|
+
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
87
|
+
name: params.name,
|
|
88
|
+
runsAt: { $lt: params.runsAt.$lt }
|
|
89
|
+
};
|
|
90
|
+
const doc = await this.runDelayedTask({
|
|
91
|
+
filter,
|
|
92
|
+
sort: params.sort,
|
|
93
|
+
executor: params.executor
|
|
94
|
+
});
|
|
95
|
+
if (doc === null) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const nameEq = params.name?.$eq;
|
|
99
|
+
let changedTask;
|
|
100
|
+
if (typeof nameEq === 'string') {
|
|
101
|
+
changedTask = {
|
|
102
|
+
id: doc.id,
|
|
103
|
+
status: factory_1.factory.taskStatus.Running,
|
|
104
|
+
name: nameEq
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
changedTask = {
|
|
109
|
+
id: doc.id,
|
|
110
|
+
status: factory_1.factory.taskStatus.Running
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask);
|
|
114
|
+
return doc;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 実行日時を一定期間過ぎたReadyタスクについて、Runningステータスに変更した上で、Runningイベントを発生させる
|
|
118
|
+
* taskNameで絞らない
|
|
119
|
+
* 2026-08-04~
|
|
120
|
+
*/
|
|
121
|
+
async emitRunningIfExistsNoName(params) {
|
|
122
|
+
if (!(params.runsAt.$lt instanceof Date)) {
|
|
123
|
+
throw new factory_1.factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
124
|
+
}
|
|
125
|
+
// インデックス'executeOneByNameIfExists'を想定したfilter
|
|
126
|
+
const filter = {
|
|
127
|
+
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
128
|
+
runsAt: { $lt: params.runsAt.$lt }
|
|
129
|
+
};
|
|
130
|
+
const doc = await this.runDelayedTask({
|
|
131
|
+
filter,
|
|
132
|
+
sort: {
|
|
133
|
+
runsAt: factory_1.factory.sortType.Ascending // ソートはrunsAtのみにしてみる(2026-08-04~)
|
|
134
|
+
},
|
|
135
|
+
executor: params.executor
|
|
136
|
+
});
|
|
137
|
+
if (doc === null) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const changedTask = {
|
|
141
|
+
id: doc.id,
|
|
142
|
+
status: factory_1.factory.taskStatus.Running
|
|
143
|
+
};
|
|
144
|
+
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask);
|
|
145
|
+
return doc;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.TaskDelayedRepo = TaskDelayedRepo;
|
|
@@ -16,7 +16,6 @@ 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';
|
|
20
19
|
import type { AdditionalPropertyRepo } from './repo/additionalProperty';
|
|
21
20
|
import type { AdminAsyncActionRepo } from './repo/adminAsyncAction';
|
|
22
21
|
import type { AdminScheduledTaskRepo } from './repo/adminScheduledTask';
|
|
@@ -93,8 +92,8 @@ import type { RateLimitSettingRepo } from './repo/setting/rateLimit';
|
|
|
93
92
|
import type { WaiterSettingRepo } from './repo/setting/waiter';
|
|
94
93
|
import type { StockHolderRepo } from './repo/stockHolder';
|
|
95
94
|
import type { ScheduledTaskRepo } from './repo/scheduledTask';
|
|
96
|
-
import type { ScheduledTaskLegacyRepo } from './repo/scheduledTaskLegacy';
|
|
97
95
|
import type { TaskRepo } from './repo/task';
|
|
96
|
+
import type { TaskDelayedRepo } from './repo/taskDelayed';
|
|
98
97
|
import type { TicketRepo } from './repo/ticket';
|
|
99
98
|
import type { TransactionRepo } from './repo/transaction';
|
|
100
99
|
import type { PlaceOrderRepo } from './repo/transaction/placeOrder';
|
|
@@ -499,22 +498,18 @@ export type ScheduledTask = ScheduledTaskRepo;
|
|
|
499
498
|
export declare namespace ScheduledTask {
|
|
500
499
|
function createInstance(...params: ConstructorParameters<typeof ScheduledTaskRepo>): Promise<ScheduledTaskRepo>;
|
|
501
500
|
}
|
|
502
|
-
export type ScheduledTaskLegacy = ScheduledTaskLegacyRepo;
|
|
503
|
-
export declare namespace ScheduledTaskLegacy {
|
|
504
|
-
function createInstance(...params: ConstructorParameters<typeof ScheduledTaskLegacyRepo>): Promise<ScheduledTaskLegacyRepo>;
|
|
505
|
-
}
|
|
506
501
|
export type Task = TaskRepo;
|
|
507
502
|
export declare namespace Task {
|
|
508
503
|
function createInstance(...params: ConstructorParameters<typeof TaskRepo>): Promise<TaskRepo>;
|
|
509
504
|
}
|
|
505
|
+
export type TaskDelayed = TaskDelayedRepo;
|
|
506
|
+
export declare namespace TaskDelayed {
|
|
507
|
+
function createInstance(...params: ConstructorParameters<typeof TaskDelayedRepo>): Promise<TaskDelayedRepo>;
|
|
508
|
+
}
|
|
510
509
|
export type AsyncAction = AsyncActionRepo;
|
|
511
510
|
export declare namespace AsyncAction {
|
|
512
511
|
function createInstance(...params: ConstructorParameters<typeof AsyncActionRepo>): Promise<AsyncActionRepo>;
|
|
513
512
|
}
|
|
514
|
-
export type AsyncActionLegacy = AsyncActionLegacyRepo;
|
|
515
|
-
export declare namespace AsyncActionLegacy {
|
|
516
|
-
function createInstance(...params: ConstructorParameters<typeof AsyncActionLegacyRepo>): Promise<AsyncActionLegacyRepo>;
|
|
517
|
-
}
|
|
518
513
|
export type Ticket = TicketRepo;
|
|
519
514
|
export declare namespace Ticket {
|
|
520
515
|
function createInstance(...params: ConstructorParameters<typeof TicketRepo>): Promise<TicketRepo>;
|