MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / ConfigManager

Class ConfigManager

packages/backend/src/configManager.ts:13–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11const logger = createLogger('config-manager');
12
13export class ConfigManager {
14 private watcher: FSWatcher;
15
16 constructor(
17 private db: PrismaClient,
18 private connectionManager: ConnectionManager,
19 configPath: string,
20 ) {
21 this.watcher = chokidar.watch(configPath, {
22 ignoreInitial: true, // Don't fire events for existing files
23 awaitWriteFinish: {
24 stabilityThreshold: 100, // File size stable for 100ms
25 pollInterval: 100 // Check every 100ms
26 },
27 atomic: true // Handle atomic writes (temp file + rename)
28 });
29
30 this.watcher.on('change', async () => {
31 logger.debug(`Config file ${configPath} changed. Syncing config.`);
32 try {
33 await this.syncConfig(configPath);
34 } catch (error) {
35 logger.error(`Failed to sync config: ${error}`);
36 }
37 });
38
39 this.syncConfig(configPath);
40 }
41
42 private syncConfig = async (configPath: string) => {
43 const config = await loadConfig(configPath);
44
45 await this.syncConnections(config.connections);
46 await syncSearchContexts({
47 contexts: config.contexts,
48 orgId: SINGLE_TENANT_ORG_ID,
49 db: this.db,
50 });
51 }
52
53 private syncConnections = async (connections?: { [key: string]: ConnectionConfig }) => {
54 if (connections) {
55 for (const [key, newConnectionConfig] of Object.entries(connections)) {
56 const existingConnection = await this.db.connection.findUnique({
57 where: {
58 name_orgId: {
59 name: key,
60 orgId: SINGLE_TENANT_ORG_ID,
61 }
62 }
63 });
64
65
66 const existingConnectionConfig = existingConnection ? existingConnection.config as unknown as ConnectionConfig : undefined;
67 const connectionNeedsSyncing =
68 !existingConnectionConfig ||
69 !isEqual(existingConnectionConfig, newConnectionConfig);
70

Callers

nothing calls this directly

Calls 3

loadConfigFunction · 0.90
syncSearchContextsFunction · 0.85
createJobsMethod · 0.45

Tested by

no test coverage detected