@chevre/domain 24.1.0-alpha.39 → 24.1.0-alpha.40
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.
|
@@ -8,12 +8,18 @@ interface IDBOptions {
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class IntegrationSettingRepo {
|
|
10
10
|
private readonly settingModel;
|
|
11
|
-
private readonly
|
|
11
|
+
private readonly defaultOptions;
|
|
12
|
+
private static cachedSettings;
|
|
13
|
+
private static cacheExpiry;
|
|
14
|
+
private static readonly CACHE_TTL_MS;
|
|
12
15
|
constructor(options: IDBOptions);
|
|
16
|
+
/**
|
|
17
|
+
* 設定全体をDBまたはキャッシュから取得する
|
|
18
|
+
*/
|
|
19
|
+
private getAllSettings;
|
|
13
20
|
/**
|
|
14
21
|
* 設定名称から設定を参照する
|
|
15
22
|
*/
|
|
16
23
|
getByKey<T extends keyof IIntegrationSettings>(key: T): Promise<IIntegrationSettings[T]>;
|
|
17
|
-
addIntegrationSettings(params: IIntegrationSettings): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
18
24
|
}
|
|
19
25
|
export {};
|
|
@@ -1,8 +1,13 @@
|
|
|
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.IntegrationSettingRepo = void 0;
|
|
7
|
+
const debug_1 = __importDefault(require("debug"));
|
|
4
8
|
const factory_1 = require("../../factory");
|
|
5
9
|
const setting_1 = require("../mongoose/schemas/setting");
|
|
10
|
+
const debug = (0, debug_1.default)('chevre-domain:repo:integrationSetting');
|
|
6
11
|
const defaultOptions = {
|
|
7
12
|
abortedTasksWithoutReport: [
|
|
8
13
|
factory_1.factory.taskName.ImportEventCapacitiesFromCOA,
|
|
@@ -33,40 +38,49 @@ const defaultOptions = {
|
|
|
33
38
|
*/
|
|
34
39
|
class IntegrationSettingRepo {
|
|
35
40
|
settingModel;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
defaultOptions;
|
|
42
|
+
// static にすることで、クラスが何回 new されてもメモリ上で1つだけ保持される
|
|
43
|
+
static cachedSettings;
|
|
44
|
+
static cacheExpiry = 0;
|
|
45
|
+
static CACHE_TTL_MS = 10 * 60 * 1000; // 10分
|
|
46
|
+
constructor(options) {
|
|
47
|
+
const { connection } = options;
|
|
43
48
|
this.settingModel = connection.model(setting_1.modelName, (0, setting_1.createSchema)());
|
|
44
|
-
this.
|
|
45
|
-
// this.options = restOptions; // defaultOptionsでひとまず固定化(2026-05-23~)
|
|
49
|
+
this.defaultOptions = defaultOptions;
|
|
46
50
|
}
|
|
47
51
|
/**
|
|
48
|
-
*
|
|
52
|
+
* 設定全体をDBまたはキャッシュから取得する
|
|
49
53
|
*/
|
|
50
|
-
async
|
|
51
|
-
const
|
|
54
|
+
async getAllSettings() {
|
|
55
|
+
const now = Date.now();
|
|
56
|
+
// static プロパティにアクセスするため、クラス名(IntegrationSettingRepo)経由で参照
|
|
57
|
+
if (IntegrationSettingRepo.cachedSettings !== undefined && now < IntegrationSettingRepo.cacheExpiry) {
|
|
58
|
+
debug('cache exist!', JSON.stringify(IntegrationSettingRepo.cachedSettings));
|
|
59
|
+
return IntegrationSettingRepo.cachedSettings;
|
|
60
|
+
}
|
|
61
|
+
const settingDoc = await this.settingModel.findOne({ 'project.id': { $eq: '*' } }, {
|
|
52
62
|
_id: 0,
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
const settingDoc = await this.settingModel.findOne({ 'project.id': { $eq: '*' } }, projection)
|
|
63
|
+
integration: 1
|
|
64
|
+
})
|
|
56
65
|
.lean()
|
|
57
66
|
.exec();
|
|
67
|
+
// キャッシュを更新
|
|
58
68
|
if (settingDoc?.integration !== undefined) {
|
|
59
|
-
|
|
69
|
+
// console.log('docuemnt exist!');
|
|
70
|
+
IntegrationSettingRepo.cachedSettings = settingDoc.integration;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
IntegrationSettingRepo.cachedSettings = this.defaultOptions;
|
|
60
74
|
}
|
|
61
|
-
|
|
75
|
+
IntegrationSettingRepo.cacheExpiry = now + IntegrationSettingRepo.CACHE_TTL_MS;
|
|
76
|
+
return IntegrationSettingRepo.cachedSettings;
|
|
62
77
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
.exec();
|
|
78
|
+
/**
|
|
79
|
+
* 設定名称から設定を参照する
|
|
80
|
+
*/
|
|
81
|
+
async getByKey(key) {
|
|
82
|
+
const settings = await this.getAllSettings();
|
|
83
|
+
return settings[key];
|
|
70
84
|
}
|
|
71
85
|
}
|
|
72
86
|
exports.IntegrationSettingRepo = IntegrationSettingRepo;
|
package/package.json
CHANGED