configurable auto-sync interval for gitea plugin
This commit is contained in:
@@ -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");
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user