You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-10 00:05:42 +02:00
Server: Improved logging and reliability of cron tasks
This commit is contained in:
@ -4,21 +4,26 @@ const cron = require('node-cron');
|
|||||||
|
|
||||||
const logger = Logger.create('cron');
|
const logger = Logger.create('cron');
|
||||||
|
|
||||||
|
async function runCronTask(name: string, callback: Function) {
|
||||||
|
const startTime = Date.now();
|
||||||
|
logger.info(`Running task "${name}"`);
|
||||||
|
try {
|
||||||
|
await callback();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`On task "${name}"`, error);
|
||||||
|
}
|
||||||
|
logger.info(`Completed task "${name}" in ${Date.now() - startTime}ms`);
|
||||||
|
}
|
||||||
|
|
||||||
export default class CronService extends BaseService {
|
export default class CronService extends BaseService {
|
||||||
|
|
||||||
public async runInBackground() {
|
public async runInBackground() {
|
||||||
cron.schedule('0 */6 * * *', async () => {
|
cron.schedule('0 */6 * * *', async () => {
|
||||||
const startTime = Date.now();
|
await runCronTask('deleteExpiredTokens', async () => this.models.token().deleteExpiredTokens());
|
||||||
logger.info('Deleting expired tokens...');
|
|
||||||
await this.models.token().deleteExpiredTokens();
|
|
||||||
logger.info(`Expired tokens deleted in ${Date.now() - startTime}ms`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cron.schedule('0 * * * *', async () => {
|
cron.schedule('0 * * * *', async () => {
|
||||||
const startTime = Date.now();
|
await runCronTask('updateTotalSizes', async () => this.models.item().updateTotalSizes());
|
||||||
logger.info('Updating total sizes...');
|
|
||||||
await this.models.item().updateTotalSizes();
|
|
||||||
logger.info(`Total sizes updated in ${Date.now() - startTime}ms`);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user