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/server/startup/cron.js

70 lines
1.5 KiB

import { Meteor } from 'meteor/meteor';
import { HTTP } from 'meteor/http';
import { SyncedCron } from 'meteor/littledata:synced-cron';
import { Logger } from '../../app/logger';
import { getWorkspaceAccessToken } from '../../app/cloud/server';
import { statistics } from '../../app/statistics';
import { settings } from '../../app/settings';
const logger = new Logger('SyncedCron');
SyncedCron.config({
logger(opts) {
return logger[opts.level].call(logger, opts.message);
},
collectionName: 'rocketchat_cron_history',
});
function generateStatistics() {
const cronStatistics = statistics.save();
cronStatistics.host = Meteor.absoluteUrl();
if (settings.get('Statistics_reporting')) {
try {
const headers = {};
const token = getWorkspaceAccessToken();
if (token) {
headers.Authorization = `Bearer ${ token }`;
}
HTTP.post('https://collector.rocket.chat/', {
data: cronStatistics,
headers,
});
} catch (error) {
/* error*/
logger.warn('Failed to send usage report');
}
}
}
function cleanupOEmbedCache() {
return Meteor.call('OEmbedCacheCleanup');
}
Meteor.startup(function() {
return Meteor.defer(function() {
generateStatistics();
SyncedCron.add({
name: 'Generate and save statistics',
schedule(parser) {
return parser.cron('12 * * * *');
},
job: generateStatistics,
});
SyncedCron.add({
name: 'Cleanup OEmbed cache',
schedule(parser) {
return parser.cron('24 2 * * *');
},
job: cleanupOEmbedCache,
});
return SyncedCron.start();
});
});