This takes part of the work being done in #96 that was reverted but still useful. Note Tailwind and Fresh weren't upgraded because there's no security vulnerability in either, and I have found the new versions to be worse in performance. Thos will likely stay at those fixed versions going forward.
40 lines
792 B
TypeScript
40 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...');
|
|
}
|