configurable auto-sync interval for gitea plugin

This commit is contained in:
2026-03-21 22:40:16 +02:00
parent 0558851427
commit 949c1331af
2 changed files with 36 additions and 1 deletions

View File

@@ -179,6 +179,25 @@ async function syncRepos(ctx) {
return { synced: repos.length, created, updated, changelogsCreated };
}
let syncTimer = null;
function startAutoSync(ctx) {
stopAutoSync();
const minutes = parseInt(ctx.config.syncInterval, 10);
if (!minutes || isNaN(minutes)) return;
ctx.logger.info({ intervalMinutes: minutes }, "gitea-sync: auto-sync enabled");
syncTimer = setInterval(() => {
syncRepos(ctx).catch((err) => ctx.logger.warn({ error: err.message }, "gitea-sync: auto-sync failed"));
}, minutes * 60 * 1000);
}
function stopAutoSync() {
if (syncTimer) {
clearInterval(syncTimer);
syncTimer = null;
}
}
export default {
routes: [
{
@@ -215,9 +234,11 @@ export default {
ctx.logger.warn({ error: err.message }, "gitea-sync: initial sync failed");
}
}
startAutoSync(ctx);
},
async onDisable(ctx) {
stopAutoSync();
ctx.logger.info("gitea-sync plugin disabled");
},
}