Browse Source

refactor(rss-scheduler): streamline plugin initialization and interval setup

- Simplified the plugin definition by removing the nitroApp parameter.
- Consolidated the interval and timeout setup for syncing feeds into a more concise format.
feat/multitenant-hub
npmrun 5 hours ago
parent
commit
596aa167d6
  1. 28
      server/plugins/04.rss-scheduler.ts

28
server/plugins/04.rss-scheduler.ts

@ -2,21 +2,19 @@ import { syncAllDueFeeds } from "#server/service/rss";
const MIN_INTERVAL_MS = 60_000; const MIN_INTERVAL_MS = 60_000;
export default defineNitroPlugin((nitroApp) => { export default defineNitroPlugin(() => {
nitroApp.hooks.hook("ready", () => { const minutes = Number(process.env.RSS_SYNC_INTERVAL_MINUTES ?? 60);
const minutes = Number(process.env.RSS_SYNC_INTERVAL_MINUTES ?? 60); const intervalMs = Math.max(minutes * 60_000, MIN_INTERVAL_MS);
const intervalMs = Math.max(minutes * 60_000, MIN_INTERVAL_MS);
setInterval(() => { setInterval(() => {
syncAllDueFeeds().catch((e) => { syncAllDueFeeds().catch((e) => {
console.error("[rss-scheduler]", e); console.error("[rss-scheduler]", e);
}); });
}, intervalMs); }, intervalMs);
setTimeout(() => { setTimeout(() => {
syncAllDueFeeds().catch((e) => { syncAllDueFeeds().catch((e) => {
console.error("[rss-scheduler] startup", e); console.error("[rss-scheduler] startup", e);
}); });
}, 5000); }, 5000);
});
}); });

Loading…
Cancel
Save