mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-11 20:05:25 +00:00
Add periodic connection re-sync (#260)
This commit is contained in:
parent
bbd8b221d6
commit
21bbe09fc9
7 changed files with 44 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.",
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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.",
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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.",
|
||||
|
|
|
|||
Loading…
Reference in a new issue