The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/server/cron/usageReport.ts

28 lines
1.1 KiB

import { cronJobs } from '@rocket.chat/cron';
import { AirGappedRestriction } from '@rocket.chat/license';
import type { Logger } from '@rocket.chat/logger';
import { Statistics } from '@rocket.chat/models';
import { sendUsageReport } from '../../app/statistics/server/functions/sendUsageReport';
export const sendUsageReportAndComputeRestriction = async (statsToken?: string) => {
// If the report failed to be sent we need to get the last existing token
// to ensure that the restriction respects the warning period.
// If no token is passed, the workspace will be instantly restricted.
const token = statsToken || (await Statistics.findLastStatsToken());
void AirGappedRestriction.computeRestriction(token);
};
export async function usageReportCron(logger: Logger): Promise<void> {
const name = 'Generate and save statistics';
const statsToken = await sendUsageReport(logger);
await sendUsageReportAndComputeRestriction(statsToken);
const now = new Date();
return cronJobs.add(name, `12 ${now.getHours()} * * *`, async () => {
const statsToken = await sendUsageReport(logger);
await sendUsageReportAndComputeRestriction(statsToken);
});
}