diff --git a/CHANGELOG.md b/CHANGELOG.md index 76cf1790..08e34740 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Change connection manager upsert timeout to 5 minutes - Fix issue with repo display names being poorly formatted, especially for gerrit. ([#259](https://github.com/sourcebot-dev/sourcebot/pull/259)) +### Added +- Added config setting `resyncConnectionIntervalMs` to control how often a connection should be re-synced. ([#260](https://github.com/sourcebot-dev/sourcebot/pull/260)) + ## [3.0.1] - 2025-04-01 ### Fixes diff --git a/docs/self-hosting/more/declarative-config.mdx b/docs/self-hosting/more/declarative-config.mdx index 3b635b8a..2e67d284 100644 --- a/docs/self-hosting/more/declarative-config.mdx +++ b/docs/self-hosting/more/declarative-config.mdx @@ -55,6 +55,11 @@ Some teams require Sourcebot to be configured via a file (where it can be stored "description": "The interval (in milliseconds) at which the indexer should re-index all repositories. Defaults to 1 hour.", "minimum": 1 }, + "resyncConnectionIntervalMs": { + "type": "number", + "description": "The interval (in milliseconds) at which the connection manager should check for connections that need to be re-synced. Defaults to 24 hours.", + "minimum": 1 + }, "resyncConnectionPollingIntervalMs": { "type": "number", "description": "The polling rate (in milliseconds) at which the db should be checked for connections that need to be re-synced. Defaults to 1 second.", diff --git a/packages/backend/src/connectionManager.ts b/packages/backend/src/connectionManager.ts index 81d184c4..1320e437 100644 --- a/packages/backend/src/connectionManager.ts +++ b/packages/backend/src/connectionManager.ts @@ -71,9 +71,29 @@ export class ConnectionManager implements IConnectionManager { public async registerPollingCallback() { setInterval(async () => { + const thresholdDate = new Date(Date.now() - this.settings.resyncConnectionIntervalMs); const connections = await this.db.connection.findMany({ where: { - syncStatus: ConnectionSyncStatus.SYNC_NEEDED, + OR: [ + // When the connection needs to be synced, we want to sync it immediately. + { + syncStatus: ConnectionSyncStatus.SYNC_NEEDED, + }, + // When the connection has already been synced, we only want to re-sync if the re-sync interval has elapsed + // (or if the date isn't set for some reason). + { + AND: [ + { OR: [ + { syncStatus: ConnectionSyncStatus.SYNCED }, + { syncStatus: ConnectionSyncStatus.SYNCED_WITH_WARNINGS }, + ]}, + { OR: [ + { syncedAt: null }, + { syncedAt: { lt: thresholdDate } }, + ]} + ] + } + ] } }); for (const connection of connections) { diff --git a/packages/backend/src/constants.ts b/packages/backend/src/constants.ts index 2973f95a..bd6246a0 100644 --- a/packages/backend/src/constants.ts +++ b/packages/backend/src/constants.ts @@ -7,6 +7,7 @@ export const DEFAULT_SETTINGS: Settings = { maxFileSize: 2 * 1024 * 1024, // 2MB in bytes maxTrigramCount: 20000, reindexIntervalMs: 1000 * 60 * 60, // 1 hour + resyncConnectionIntervalMs: 1000 * 60 * 60 * 24, // 24 hours resyncConnectionPollingIntervalMs: 1000 * 1, // 1 second reindexRepoPollingIntervalMs: 1000 * 1, // 1 second maxConnectionSyncJobConcurrency: 8, diff --git a/packages/schemas/src/v3/index.schema.ts b/packages/schemas/src/v3/index.schema.ts index 86425497..f8b9258c 100644 --- a/packages/schemas/src/v3/index.schema.ts +++ b/packages/schemas/src/v3/index.schema.ts @@ -23,6 +23,11 @@ const schema = { "description": "The interval (in milliseconds) at which the indexer should re-index all repositories. Defaults to 1 hour.", "minimum": 1 }, + "resyncConnectionIntervalMs": { + "type": "number", + "description": "The interval (in milliseconds) at which the connection manager should check for connections that need to be re-synced. Defaults to 24 hours.", + "minimum": 1 + }, "resyncConnectionPollingIntervalMs": { "type": "number", "description": "The polling rate (in milliseconds) at which the db should be checked for connections that need to be re-synced. Defaults to 1 second.", diff --git a/packages/schemas/src/v3/index.type.ts b/packages/schemas/src/v3/index.type.ts index b7b9c1c9..01c6c668 100644 --- a/packages/schemas/src/v3/index.type.ts +++ b/packages/schemas/src/v3/index.type.ts @@ -39,6 +39,10 @@ export interface Settings { * The interval (in milliseconds) at which the indexer should re-index all repositories. Defaults to 1 hour. */ reindexIntervalMs?: number; + /** + * The interval (in milliseconds) at which the connection manager should check for connections that need to be re-synced. Defaults to 24 hours. + */ + resyncConnectionIntervalMs?: number; /** * The polling rate (in milliseconds) at which the db should be checked for connections that need to be re-synced. Defaults to 1 second. */ diff --git a/schemas/v3/index.json b/schemas/v3/index.json index 8119ad54..45a3b029 100644 --- a/schemas/v3/index.json +++ b/schemas/v3/index.json @@ -23,6 +23,11 @@ "description": "The interval (in milliseconds) at which the indexer should re-index all repositories. Defaults to 1 hour.", "minimum": 1 }, + "resyncConnectionIntervalMs": { + "type": "number", + "description": "The interval (in milliseconds) at which the connection manager should check for connections that need to be re-synced. Defaults to 24 hours.", + "minimum": 1 + }, "resyncConnectionPollingIntervalMs": { "type": "number", "description": "The polling rate (in milliseconds) at which the db should be checked for connections that need to be re-synced. Defaults to 1 second.",