Skip to content

Commit 6ecaa86

Browse files
Add resyncConnectionIntervalMs
1 parent bbd8b22 commit 6ecaa86

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

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)