|
|
@@ -3,7 +3,6 @@ import nodeCron from 'node-cron';
|
|
|
import { AccessToken } from '~/server/models/access-token';
|
|
|
import { configManager } from '~/server/service/config-manager';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
-import { getRandomIntInRange } from '~/utils/rand';
|
|
|
|
|
|
const logger = loggerFactory('growi:service:access-token-deletion-cron');
|
|
|
|
|
|
@@ -14,14 +13,11 @@ export class AccessTokenDeletionCronService {
|
|
|
// デフォルトで毎日深夜0時に実行 (UTC で 15:00)
|
|
|
accessTokenDeletionCronExpression = '0 15 * * *';
|
|
|
|
|
|
- // デフォルトで最大30分のランダム遅延
|
|
|
- accessTokenDeletionCronMaxMinutesUntilRequest = 30;
|
|
|
-
|
|
|
- sleep = (msec: number): Promise<void> => new Promise(resolve => setTimeout(resolve, msec));
|
|
|
-
|
|
|
startCron(): void {
|
|
|
- this.accessTokenDeletionCronExpression = configManager.getConfig('accessToken:deletionCronExpression');
|
|
|
- this.accessTokenDeletionCronMaxMinutesUntilRequest = configManager.getConfig('accessToken:deletionCronMaxMinutesUntilRequest');
|
|
|
+ const cronExp = configManager.getConfig('accessToken:deletionCronExpression');
|
|
|
+ if (cronExp != null) {
|
|
|
+ this.accessTokenDeletionCronExpression = cronExp;
|
|
|
+ }
|
|
|
|
|
|
this.cronJob?.stop();
|
|
|
this.cronJob = this.generateCronJob();
|
|
|
@@ -43,10 +39,6 @@ export class AccessTokenDeletionCronService {
|
|
|
private generateCronJob() {
|
|
|
return nodeCron.schedule(this.accessTokenDeletionCronExpression, async() => {
|
|
|
try {
|
|
|
- // Random fractional sleep to distribute request timing among GROWI apps
|
|
|
- const randomMilliseconds = getRandomIntInRange(0, this.accessTokenDeletionCronMaxMinutesUntilRequest) * 60 * 1000;
|
|
|
- await this.sleep(randomMilliseconds);
|
|
|
-
|
|
|
await this.executeJob();
|
|
|
}
|
|
|
catch (e) {
|