Skip to content

Commit 21bbe09

Browse files
Add periodic connection re-sync (#260)
1 parent bbd8b22 commit 21bbe09

File tree

7 files changed

+44
-1
lines changed

7 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Change connection manager upsert timeout to 5 minutes
1212
- Fix issue with repo display names being poorly formatted, especially for gerrit. ([#259](https://github.com/sourcebot-dev/sourcebot/pull/259))
1313

14+
### Added
15+
- Added config setting `resyncConnectionIntervalMs` to control how often a connection should be re-synced. ([#260](https://github.com/sourcebot-dev/sourcebot/pull/260))
16+
1417
## [3.0.1] - 2025-04-01
1518

1619
### Fixes

docs/self-hosting/more/declarative-config.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ Some teams require Sourcebot to be configured via a file (where it can be stored
5555
"description": "The interval (in milliseconds) at which the indexer should re-index all repositories. Defaults to 1 hour.",
5656
"minimum": 1
5757
},
58+
"resyncConnectionIntervalMs": {
59+
"type": "number",
60+
"description": "The interval (in milliseconds) at which the connection manager should check for connections that need to be re-synced. Defaults to 24 hours.",
61+
"minimum": 1
62+
},
5863
"resyncConnectionPollingIntervalMs": {
5964
"type": "number",
6065
"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.",

packages/backend/src/connectionManager.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,29 @@ export class ConnectionManager implements IConnectionManager {
7171

7272
public async registerPollingCallback() {
7373
setInterval(async () => {
74+
const thresholdDate = new Date(Date.now() - this.settings.resyncConnectionIntervalMs);
7475
const connections = await this.db.connection.findMany({
7576
where: {
76-
syncStatus: ConnectionSyncStatus.SYNC_NEEDED,
77+
OR: [
78+
// When the connection needs to be synced, we want to sync it immediately.
79+
{
80+
syncStatus: ConnectionSyncStatus.SYNC_NEEDED,
81+
},
82+
// When the connection has already been synced, we only want to re-sync if the re-sync interval has elapsed
83+
// (or if the date isn't set for some reason).
84+
{
85+
AND: [
86+
{ OR: [
87+
{ syncStatus: ConnectionSyncStatus.SYNCED },
88+
{ syncStatus: ConnectionSyncStatus.SYNCED_WITH_WARNINGS },
89+
]},
90+
{ OR: [
91+
{ syncedAt: null },
92+
{ syncedAt: { lt: thresholdDate } },
93+
]}
94+
]
95+
}
96+
]
7797
}
7898
});
7999
for (const connection of connections) {

packages/backend/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const DEFAULT_SETTINGS: Settings = {
77
maxFileSize: 2 * 1024 * 1024, // 2MB in bytes
88
maxTrigramCount: 20000,
99
reindexIntervalMs: 1000 * 60 * 60, // 1 hour
10+
resyncConnectionIntervalMs: 1000 * 60 * 60 * 24, // 24 hours
1011
resyncConnectionPollingIntervalMs: 1000 * 1, // 1 second
1112
reindexRepoPollingIntervalMs: 1000 * 1, // 1 second
1213
maxConnectionSyncJobConcurrency: 8,

packages/schemas/src/v3/index.schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ const schema = {
2323
"description": "The interval (in milliseconds) at which the indexer should re-index all repositories. Defaults to 1 hour.",
2424
"minimum": 1
2525
},
26+
"resyncConnectionIntervalMs": {
27+
"type": "number",
28+
"description": "The interval (in milliseconds) at which the connection manager should check for connections that need to be re-synced. Defaults to 24 hours.",
29+
"minimum": 1
30+
},
2631
"resyncConnectionPollingIntervalMs": {
2732
"type": "number",
2833
"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.",

packages/schemas/src/v3/index.type.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export interface Settings {
3939
* The interval (in milliseconds) at which the indexer should re-index all repositories. Defaults to 1 hour.
4040
*/
4141
reindexIntervalMs?: number;
42+
/**
43+
* The interval (in milliseconds) at which the connection manager should check for connections that need to be re-synced. Defaults to 24 hours.
44+
*/
45+
resyncConnectionIntervalMs?: number;
4246
/**
4347
* The polling rate (in milliseconds) at which the db should be checked for connections that need to be re-synced. Defaults to 1 second.
4448
*/

schemas/v3/index.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
"description": "The interval (in milliseconds) at which the indexer should re-index all repositories. Defaults to 1 hour.",
2424
"minimum": 1
2525
},
26+
"resyncConnectionIntervalMs": {
27+
"type": "number",
28+
"description": "The interval (in milliseconds) at which the connection manager should check for connections that need to be re-synced. Defaults to 24 hours.",
29+
"minimum": 1
30+
},
2631
"resyncConnectionPollingIntervalMs": {
2732
"type": "number",
2833
"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.",

0 commit comments

Comments
 (0)