138 lines
4.1 KiB
TypeScript
138 lines
4.1 KiB
TypeScript
import * as plugins from '../plugins.js';
|
|
import { Reception } from './classes.reception.js';
|
|
import { logger } from './logging.js';
|
|
|
|
export class ReceptionHousekeeping {
|
|
public receptionRef: Reception;
|
|
public taskmanager = new plugins.taskbuffer.TaskManager();
|
|
|
|
constructor(receptionArg: Reception) {
|
|
this.receptionRef = receptionArg;
|
|
|
|
// lets care about old loginsessions
|
|
this.taskmanager.addAndScheduleTask(
|
|
new plugins.taskbuffer.Task({
|
|
name: 'oldLoginSessions',
|
|
taskFunction: async () => {
|
|
logger.log('info', 'running login sessions cleaning task');
|
|
const oneWeekBeforeTimestamp =
|
|
Date.now() - plugins.smarttime.getMilliSecondsFromUnits({ weeks: 1 });
|
|
const oldLoginSessions =
|
|
await this.receptionRef.loginSessionManager.CLoginSession.getInstances({
|
|
data: {
|
|
validUntil: {
|
|
$lt: oneWeekBeforeTimestamp,
|
|
} as any,
|
|
},
|
|
});
|
|
for (const loginSession of oldLoginSessions) {
|
|
await loginSession.delete();
|
|
}
|
|
logger.log('info', `Completed deletion of ${oldLoginSessions.length} old loginSessions`);
|
|
},
|
|
}),
|
|
'2 * * * * *'
|
|
);
|
|
|
|
this.taskmanager.addAndScheduleTask(
|
|
new plugins.taskbuffer.Task({
|
|
name: 'expiredEmailActionTokens',
|
|
taskFunction: async () => {
|
|
const expiredEmailActionTokens =
|
|
await this.receptionRef.loginSessionManager.CEmailActionToken.getInstances({
|
|
data: {
|
|
validUntil: {
|
|
$lt: Date.now(),
|
|
} as any,
|
|
},
|
|
});
|
|
for (const emailActionToken of expiredEmailActionTokens) {
|
|
await emailActionToken.delete();
|
|
}
|
|
},
|
|
}),
|
|
'2 * * * * *'
|
|
);
|
|
|
|
this.taskmanager.addAndScheduleTask(
|
|
new plugins.taskbuffer.Task({
|
|
name: 'expiredRegistrationSessions',
|
|
taskFunction: async () => {
|
|
const expiredRegistrationSessions =
|
|
await this.receptionRef.registrationSessionManager.CRegistrationSession.getInstances({
|
|
data: {
|
|
validUntil: {
|
|
$lt: Date.now(),
|
|
} as any,
|
|
},
|
|
});
|
|
for (const registrationSession of expiredRegistrationSessions) {
|
|
await registrationSession.delete();
|
|
}
|
|
},
|
|
}),
|
|
'2 * * * * *'
|
|
);
|
|
|
|
this.taskmanager.addAndScheduleTask(
|
|
new plugins.taskbuffer.Task({
|
|
name: 'expiredAbuseWindows',
|
|
taskFunction: async () => {
|
|
const expiredAbuseWindows =
|
|
await this.receptionRef.abuseProtectionManager.CAbuseWindow.getInstances({
|
|
data: {
|
|
validUntil: {
|
|
$lt: Date.now(),
|
|
} as any,
|
|
},
|
|
});
|
|
for (const abuseWindow of expiredAbuseWindows) {
|
|
await abuseWindow.delete();
|
|
}
|
|
},
|
|
}),
|
|
'2 * * * * *'
|
|
);
|
|
|
|
this.taskmanager.addAndScheduleTask(
|
|
new plugins.taskbuffer.Task({
|
|
name: 'expiredPassportChallenges',
|
|
taskFunction: async () => {
|
|
await this.receptionRef.passportManager.cleanupExpiredChallenges();
|
|
},
|
|
}),
|
|
'2 * * * * *'
|
|
);
|
|
|
|
this.taskmanager.addAndScheduleTask(
|
|
new plugins.taskbuffer.Task({
|
|
name: 'redeliverPassportChallengeHints',
|
|
taskFunction: async () => {
|
|
await this.receptionRef.passportManager.reDeliverPendingChallengeHints();
|
|
},
|
|
}),
|
|
'7 * * * * *'
|
|
);
|
|
|
|
this.taskmanager.addAndScheduleTask(
|
|
new plugins.taskbuffer.Task({
|
|
name: 'redeliverAlertHints',
|
|
taskFunction: async () => {
|
|
await this.receptionRef.alertManager.reDeliverPendingAlerts();
|
|
},
|
|
}),
|
|
'12 * * * * *'
|
|
);
|
|
}
|
|
|
|
public async start() {
|
|
this.taskmanager.start();
|
|
logger.log('info', 'housekeeping started');
|
|
}
|
|
|
|
public async stop() {
|
|
this.taskmanager.stop();
|
|
logger.log('info', 'housekeeping stopped');
|
|
}
|
|
}
|