bewcloud/crons/index.ts
Bruno Bernardino 986573cfc9
Upgrade Fresh to v2
Also upgrade all dependencies, make some unnecessary, and some other small tweaks.

Because this has a big potential of unexpectedly breaking things, I'm doing a "breaking release", v3.
2025-09-26 18:48:02 +01:00

39 lines
792 B
TypeScript

import { Cron } from '@hexagon/croner';
import { AppConfig } from '/lib/config.ts';
import { cleanupSessions } from './sessions.ts';
import { cleanupOldArticles, fetchNewArticles } from './news.ts';
export async function startCrons() {
new Cron(
// At 03:06 every day.
'6 3 * * *',
{
name: 'cleanup',
protect: true,
},
async () => {
await cleanupSessions();
if (await AppConfig.isAppEnabled('news')) {
await cleanupOldArticles();
}
},
);
if (await AppConfig.isAppEnabled('news')) {
new Cron(
// Every 30 minutes.
'*/30 * * * *',
{
name: 'news',
protect: true,
},
async () => {
await fetchNewArticles();
},
);
}
console.log('Crons starting...');
}