소스 검색

fix configManager usage

荒井風太 1 년 전
부모
커밋
57f0dd91be

+ 2 - 2
apps/app/src/features/page-bulk-export/server/service/check-page-bulk-export-job-in-progress-cron.ts

@@ -16,11 +16,11 @@ const logger = loggerFactory('growi:service:check-page-bulk-export-job-in-progre
 class CheckPageBulkExportJobInProgressCronService extends CronService {
 
   override getCronSchedule(): string {
-    return configManager.getConfig('crowi', 'app:checkPageBulkExportJobInProgressCronSchedule');
+    return configManager.getConfig('app:checkPageBulkExportJobInProgressCronSchedule');
   }
 
   override async executeJob(): Promise<void> {
-    const isBulkExportPagesEnabled = configManager.getConfig('crowi', 'app:isBulkExportPagesEnabled');
+    const isBulkExportPagesEnabled = configManager.getConfig('app:isBulkExportPagesEnabled');
     if (!isBulkExportPagesEnabled) return;
 
     const pageBulkExportJobInProgress = await PageBulkExportJob.findOne({

+ 2 - 2
apps/app/src/features/page-bulk-export/server/service/page-bulk-export-job-clean-up-cron.integ.ts

@@ -51,7 +51,7 @@ describe('PageBulkExportJobCleanUpCronService', () => {
     const jobId3 = new mongoose.Types.ObjectId();
     const jobId4 = new mongoose.Types.ObjectId();
     beforeEach(async() => {
-      await configManager.updateConfigsInTheSameNamespace('crowi', { 'app:bulkExportJobExpirationSeconds': 86400 }); // 1 day
+      await configManager.updateConfig('app:bulkExportJobExpirationSeconds', 86400); // 1 day
 
       await PageBulkExportJob.insertMany([
         {
@@ -104,7 +104,7 @@ describe('PageBulkExportJobCleanUpCronService', () => {
     const jobId3 = new mongoose.Types.ObjectId();
     const jobId4 = new mongoose.Types.ObjectId();
     beforeEach(async() => {
-      await configManager.updateConfigsInTheSameNamespace('crowi', { 'app:bulkExportDownloadExpirationSeconds': 86400 }); // 1 day
+      await configManager.updateConfig('app:bulkExportDownloadExpirationSeconds', 86400); // 1 day
 
       await PageBulkExportJob.insertMany([
         {

+ 3 - 3
apps/app/src/features/page-bulk-export/server/service/page-bulk-export-job-clean-up-cron.ts

@@ -26,7 +26,7 @@ class PageBulkExportJobCleanUpCronService extends CronService {
   }
 
   override getCronSchedule(): string {
-    return configManager.getConfig('crowi', 'app:pageBulkExportJobCleanUpCronSchedule');
+    return configManager.getConfig('app:pageBulkExportJobCleanUpCronSchedule');
   }
 
   override async executeJob(): Promise<void> {
@@ -41,7 +41,7 @@ class PageBulkExportJobCleanUpCronService extends CronService {
    * Delete bulk export jobs which are on-going and has passed the limit time for execution
    */
   async deleteExpiredExportJobs() {
-    const exportJobExpirationSeconds = configManager.getConfig('crowi', 'app:bulkExportJobExpirationSeconds');
+    const exportJobExpirationSeconds = configManager.getConfig('app:bulkExportJobExpirationSeconds');
     const expiredExportJobs = await PageBulkExportJob.find({
       $or: Object.values(PageBulkExportJobInProgressStatus).map(status => ({ status })),
       createdAt: { $lt: new Date(Date.now() - exportJobExpirationSeconds * 1000) },
@@ -56,7 +56,7 @@ class PageBulkExportJobCleanUpCronService extends CronService {
    * Delete bulk export jobs which have completed but the due time for downloading has passed
    */
   async deleteDownloadExpiredExportJobs() {
-    const downloadExpirationSeconds = configManager.getConfig('crowi', 'app:bulkExportDownloadExpirationSeconds');
+    const downloadExpirationSeconds = configManager.getConfig('app:bulkExportDownloadExpirationSeconds');
     const thresholdDate = new Date(Date.now() - downloadExpirationSeconds * 1000);
     const downloadExpiredExportJobs = await PageBulkExportJob.find({
       status: PageBulkExportJobStatus.completed,

+ 2 - 2
apps/app/src/features/page-bulk-export/server/service/page-bulk-export-job-cron/index.ts

@@ -75,11 +75,11 @@ class PageBulkExportJobCronService extends CronService implements IPageBulkExpor
     super();
     this.crowi = crowi;
     this.activityEvent = crowi.event('activity');
-    this.parallelExecLimit = configManager.getConfig('crowi', 'app:pageBulkExportParallelExecLimit');
+    this.parallelExecLimit = configManager.getConfig('app:pageBulkExportParallelExecLimit');
   }
 
   override getCronSchedule(): string {
-    return configManager.getConfig('crowi', 'app:pageBulkExportJobCronSchedule');
+    return configManager.getConfig('app:pageBulkExportJobCronSchedule');
   }
 
   override async executeJob(): Promise<void> {

+ 4 - 4
apps/app/src/server/routes/apiv3/app-settings.js

@@ -499,7 +499,7 @@ module.exports = (crowi) => {
       isMaintenanceMode: configManager.getConfig('app:isMaintenanceMode'),
 
       isBulkExportPagesEnabled: crowi.configManager.getConfig('app:isBulkExportPagesEnabled'),
-      envIsBulkExportPagesEnabled: crowi.configManager.getConfigFromEnvVars('app:isBulkExportPagesEnabled'),
+      envIsBulkExportPagesEnabled: crowi.configManager.getConfig('app:isBulkExportPagesEnabled'),
       bulkExportDownloadExpirationSeconds: crowi.configManager.getConfig('app:bulkExportDownloadExpirationSeconds'),
     };
     return res.apiv3({ appSettingsParams });
@@ -1036,10 +1036,10 @@ module.exports = (crowi) => {
       };
 
       try {
-        await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams, true);
+        await crowi.configManager.updateConfigs(requestParams, { skipPubsub: true });
         const responseParams = {
-          isBulkExportPagesEnabled: crowi.configManager.getConfig('crowi', 'app:isBulkExportPagesEnabled'),
-          bulkExportDownloadExpirationSeconds: crowi.configManager.getConfig('crowi', 'app:bulkExportDownloadExpirationSeconds'),
+          isBulkExportPagesEnabled: crowi.configManager.getConfig('app:isBulkExportPagesEnabled'),
+          bulkExportDownloadExpirationSeconds: crowi.configManager.getConfig('app:bulkExportDownloadExpirationSeconds'),
         };
 
         const parameters = { action: SupportedAction.ACTION_ADMIN_APP_SETTINGS_UPDATE };

+ 42 - 0
apps/app/src/server/service/config-manager/config-definition.ts

@@ -317,6 +317,16 @@ export const CONFIG_KEYS = [
   'env:useOnlyEnvVars:gcs',
   'env:useOnlyEnvVars:azure',
 
+  // Page Bulk Export Settings
+  'app:bulkExportJobExpirationSeconds',
+  'app:bulkExportDownloadExpirationSeconds',
+  'app:pageBulkExportJobCronSchedule',
+  'app:checkPageBulkExportJobInProgressCronSchedule',
+  'app:pageBulkExportJobCleanUpCronSchedule',
+  'app:pageBulkExportParallelExecLimit',
+  'app:isBulkExportPagesEnabled',
+  'env:useOnlyEnvVars:app:isBulkExportPagesEnabled',
+
 ] as const;
 
 
@@ -1280,6 +1290,38 @@ Guideline as a RAG:
     envVarName: 'AZURE_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS',
     defaultValue: false,
   }),
+  'app:bulkExportJobExpirationSeconds': defineConfig<number>({
+    envVarName: 'BULK_EXPORT_JOB_EXPIRATION_SECONDS',
+    defaultValue: 86400,
+  }),
+  'app:bulkExportDownloadExpirationSeconds': defineConfig<number>({
+    envVarName: 'BULK_EXPORT_DOWNLOAD_EXPIRATION_SECONDS',
+    defaultValue: 259200,
+  }),
+  'app:pageBulkExportJobCronSchedule': defineConfig<string>({
+    envVarName: 'BULK_EXPORT_JOB_CRON_SCHEDULE',
+    defaultValue: '*/10 * * * *',
+  }),
+  'app:checkPageBulkExportJobInProgressCronSchedule': defineConfig<string>({
+    envVarName: 'CHECK_PAGE_BULK_EXPORT_JOB_IN_PROGRESS_CRON_SCHEDULE',
+    defaultValue: '*/3 * * * *',
+  }),
+  'app:pageBulkExportJobCleanUpCronSchedule': defineConfig<string>({
+    envVarName: 'BULK_EXPORT_JOB_CLEAN_UP_CRON_SCHEDULE',
+    defaultValue: '*/10 * * * *',
+  }),
+  'app:pageBulkExportParallelExecLimit': defineConfig<number>({
+    envVarName: 'BULK_EXPORT_PARALLEL_EXEC_LIMIT',
+    defaultValue: 5,
+  }),
+  'app:isBulkExportPagesEnabled': defineConfig<boolean>({
+    envVarName: 'BULK_EXPORT_PAGES_ENABLED',
+    defaultValue: true,
+  }),
+  'env:useOnlyEnvVars:app:isBulkExportPagesEnabled': defineConfig<boolean>({
+    envVarName: 'BULK_EXPORT_PAGES_ENABLED_USES_ONLY_ENV_VARS',
+    defaultValue: false,
+  }),
 } as const;
 
 export type ConfigValues = {

+ 2 - 2
apps/app/src/server/service/file-uploader/gcs/multipart-uploader.ts

@@ -22,8 +22,8 @@ export class GcsMultipartUploader extends MultipartUploader implements IGcsMulti
   constructor(bucket: Bucket, uploadKey: string, maxPartSize: number) {
     super(uploadKey, maxPartSize);
 
-    const namespace = configManager.getConfig('crowi', 'gcs:uploadNamespace');
-    this.file = bucket.file(urljoin(namespace || '', uploadKey));
+    const namespace = configManager.getConfig('gcs:uploadNamespace');
+    this.file = bucket.file(urljoin(namespace, uploadKey));
   }
 
   async initUpload(): Promise<void> {