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

refs 111686: questionnaire cronjob

Futa Arai 3 лет назад
Родитель
Сommit
ea5c0266bf

+ 1 - 0
packages/app/.env.development

@@ -17,6 +17,7 @@ ELASTICSEARCH_REJECT_UNAUTHORIZED=true
 HACKMD_URI="http://localhost:3010"
 HACKMD_URI_FOR_SERVER="http://hackmd:3000"
 OGP_URI="http://ogp:8088"
+GROWI_QUESTIONNAIRE_URI="http://host.docker.internal:3003"
 # DRAWIO_URI="http://localhost:8080/?offline=1&https=0"
 # S2SMSG_PUBSUB_SERVER_TYPE=nchan
 # PUBLISH_OPEN_API=true

+ 1 - 0
packages/app/package.json

@@ -139,6 +139,7 @@
     "next-superjson": "^0.0.4",
     "next-themes": "^0.2.0",
     "nocache": "^3.0.1",
+    "node-cron": "^3.0.2",
     "nodemailer": "^6.6.2",
     "nodemailer-ses-transport": "~1.5.0",
     "openid-client": "^5.1.2",

+ 11 - 0
packages/app/src/server/crowi/index.js

@@ -29,11 +29,13 @@ import PageGrantService from '../service/page-grant';
 import PageOperationService from '../service/page-operation';
 // eslint-disable-next-line import/no-cycle
 import { PluginService } from '../service/plugin';
+import QuestionnaireCronService from '../service/questionnnaire-cron-service';
 import SearchService from '../service/search';
 import { SlackIntegrationService } from '../service/slack-integration';
 import { UserNotificationService } from '../service/user-notification';
 import { initMongooseGlobalSettings, getMongoUri, mongoOptions } from '../util/mongoose-utils';
 
+
 const logger = loggerFactory('growi:crowi');
 const httpErrorHandler = require('../middlewares/http-error-handler');
 const models = require('../models');
@@ -105,6 +107,7 @@ Crowi.prototype.init = async function() {
   await this.setupModels();
   await this.setupConfigManager();
   await this.setupSessionConfig();
+  await this.setupCron();
 
   // setup messaging services
   await this.setupS2sMessagingService();
@@ -304,6 +307,14 @@ Crowi.prototype.setupModels = async function() {
   });
 };
 
+Crowi.prototype.setupCron = function() {
+  new QuestionnaireCronService(
+    this.configManager.getConfig('crowi', 'app:growiQuestionnaireUri'),
+    this.configManager.getConfig('crowi', 'app:questionnaireCronSchedule'),
+    this.configManager.getConfig('crowi', 'app:questionnaireCronMaxHoursUntilRequest'),
+  ).setUpCron();
+};
+
 Crowi.prototype.scanRuntimeVersions = async function() {
   const self = this;
 

+ 18 - 0
packages/app/src/server/service/config-loader.ts

@@ -664,6 +664,24 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type: ValueType.STRING,
     default: null,
   },
+  GROWI_QUESTIONNAIRE_URI: {
+    ns: 'crowi',
+    key: 'app:growiQuestionnaireUri',
+    type: ValueType.STRING,
+    default: null,
+  },
+  QUESTIONNAIRE_CRON_SCHEDULE: {
+    ns: 'crowi',
+    key: 'app:questionnaireCronSchedule',
+    type: ValueType.STRING,
+    default: '0 22 * * *',
+  },
+  QUESTIONNAIRE_CRON_MAX_HOURS_UNTIL_REQUEST: {
+    ns: 'crowi',
+    key: 'app:questionnaireCronMaxHoursUntilRequest',
+    type: ValueType.NUMBER,
+    default: 4,
+  },
 };