Просмотр исходного кода

get cron schedule inside service

Futa Arai 1 год назад
Родитель
Сommit
c24165c243

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

@@ -23,6 +23,10 @@ class PageBulkExportJobCronService extends CronService {
     this.crowi = crowi;
   }
 
+  override getCronSchedule(): string {
+    return configManager.getConfig('crowi', 'app:pageBulkExportJobCronSchedule');
+  }
+
   override async executeJob(): Promise<void> {
     await this.deleteExpiredExportJobs();
     await this.deleteDownloadExpiredExportJobs();

+ 2 - 2
apps/app/src/features/questionnaire/server/service/questionnaire-cron.ts

@@ -26,8 +26,8 @@ class QuestionnaireCronService extends CronService {
 
   sleep = (msec: number): Promise<void> => new Promise(resolve => setTimeout(resolve, msec));
 
-  override startCron(cronSchedule: string): void {
-    super.startCron(cronSchedule);
+  override getCronSchedule(): string {
+    return configManager.getConfig('crowi', 'app:questionnaireCronSchedule');
   }
 
   override async executeJob(): Promise<void> {

+ 2 - 4
apps/app/src/server/crowi/index.js

@@ -327,12 +327,10 @@ Crowi.prototype.setupModels = async function() {
 };
 
 Crowi.prototype.setupCron = function() {
-  const questionnaireCronSchedule = this.configManager.getConfig('crowi', 'app:questionnaireCronSchedule');
-  questionnaireCronService.startCron(questionnaireCronSchedule);
+  questionnaireCronService.startCron();
 
   instanciatePageBulkExportJobCronService(this);
-  const pageBulkExportJobCronSchedule = this.configManager.getConfig('crowi', 'app:pageBulkExportJobCronSchedule');
-  pageBulkExportJobCronService.startCron(pageBulkExportJobCronSchedule);
+  pageBulkExportJobCronService.startCron();
 };
 
 Crowi.prototype.setupQuestionnaireService = function() {

+ 8 - 3
apps/app/src/server/service/cron.ts

@@ -15,11 +15,10 @@ abstract class CronService {
 
   /**
    * Create and start a new cronjob
-   * @param cronSchedule e.g. '0 1 * * *'
    */
-  startCron(cronSchedule: string): void {
+  startCron(): void {
     this.cronJob?.stop();
-    this.cronJob = this.generateCronJob(cronSchedule);
+    this.cronJob = this.generateCronJob(this.getCronSchedule());
     this.cronJob.start();
   }
 
@@ -30,6 +29,12 @@ abstract class CronService {
     this.cronJob.stop();
   }
 
+  /**
+   * Get the cron schedule
+   * e.g. '0 1 * * *'
+   */
+  abstract getCronSchedule(): string;
+
   /**
    * Execute the job. Define the job process in the subclass.
    */