* Implement a more robust Config This moves the configuration variables from the `.env` file to a new `bewcloud.config.ts` file. Note that DB connection and secrets are still in the `.env` file. This will allow for more reliable and easier personalized configurations, and was a requirement to start working on adding SSO (#13). For now, `.env`-based config will still be allowed and respected (overriden by `bewcloud.config.ts`), but in the future I'll probably remove it (some major upgrade). * Update deploy script to also copy the new config file
40 lines
824 B
TypeScript
40 lines
824 B
TypeScript
import { Cron } from 'https://deno.land/x/croner@8.1.2/dist/croner.js';
|
|
|
|
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...');
|
|
}
|