Fix bug with multiple cleanup connections being scheduled

This commit is contained in:
bkellam 2025-10-28 17:22:17 -07:00
parent 28da73e292
commit aa56ee64aa

View file

@ -149,7 +149,8 @@ export class RepoIndexManager {
} }
private async scheduleCleanupJobs() { private async scheduleCleanupJobs() {
const thresholdDate = new Date(Date.now() - this.settings.repoGarbageCollectionGracePeriodMs); const gcGracePeriodMs = new Date(Date.now() - this.settings.repoGarbageCollectionGracePeriodMs);
const timeoutDate = new Date(Date.now() - this.settings.repoIndexTimeoutMs);
const reposToCleanup = await this.db.repo.findMany({ const reposToCleanup = await this.db.repo.findMany({
where: { where: {
@ -158,9 +159,8 @@ export class RepoIndexManager {
}, },
OR: [ OR: [
{ indexedAt: null }, { indexedAt: null },
{ indexedAt: { lt: thresholdDate } }, { indexedAt: { lt: gcGracePeriodMs } },
], ],
// Don't schedule if there are active jobs that were created within the threshold date.
NOT: { NOT: {
jobs: { jobs: {
some: { some: {
@ -178,7 +178,7 @@ export class RepoIndexManager {
}, },
{ {
createdAt: { createdAt: {
gt: thresholdDate, gt: timeoutDate,
} }
} }
] ]