mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-20 00:05:22 +00:00
## Problem If a repository is added **after** a search context (e.g., a new repository is synced from the code host), then it will never be added to the context even if it should be included. The workaround is to restart the instance. ## Solution This PR adds a call to re-sync all search contexts whenever a connection is successfully synced. This PR adds the `@sourcebot/shared` package that contains `syncSearchContexts.ts` (previously in web) and it's dependencies (namely the entitlements system). ## Why another package? Because the `syncSearchContexts` call is now called from: 1. `initialize.ts` in **web** - handles syncing search contexts on startup and whenever the config is modified in watch mode. This is the same as before. 2. `connectionManager.ts` in **backend** - syncs the search contexts whenever a connection is successfully synced. ## Follow-up devex work Two things: 1. We have several very thin shared packages (i.e., `crypto`, `error`, and `logger`) that we can probably fold into this "general" shared package. `schemas` and `db` _feels_ like they should remain separate (mostly because they are "code-gen" packages). 2. When running `yarn dev`, any changes made to the shared package will only get picked if you `ctrl+c` and restart the instance. Would be nice if we have watch mode work across package dependencies in the monorepo.
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { PrismaClient } from '@sourcebot/db';
|
|
import { createLogger } from "@sourcebot/logger";
|
|
import { AppContext } from "./types.js";
|
|
import { DEFAULT_SETTINGS } from './constants.js';
|
|
import { Redis } from 'ioredis';
|
|
import { ConnectionManager } from './connectionManager.js';
|
|
import { RepoManager } from './repoManager.js';
|
|
import { env } from './env.js';
|
|
import { PromClient } from './promClient.js';
|
|
import { loadConfig } from '@sourcebot/shared';
|
|
|
|
const logger = createLogger('backend-main');
|
|
|
|
const getSettings = async (configPath?: string) => {
|
|
if (!configPath) {
|
|
return DEFAULT_SETTINGS;
|
|
}
|
|
|
|
const config = await loadConfig(configPath);
|
|
|
|
return {
|
|
...DEFAULT_SETTINGS,
|
|
...config.settings,
|
|
}
|
|
}
|
|
|
|
export const main = async (db: PrismaClient, context: AppContext) => {
|
|
const redis = new Redis(env.REDIS_URL, {
|
|
maxRetriesPerRequest: null
|
|
});
|
|
redis.ping().then(() => {
|
|
logger.info('Connected to redis');
|
|
}).catch((err: unknown) => {
|
|
logger.error('Failed to connect to redis');
|
|
logger.error(err);
|
|
process.exit(1);
|
|
});
|
|
|
|
const settings = await getSettings(env.CONFIG_PATH);
|
|
|
|
const promClient = new PromClient();
|
|
|
|
const connectionManager = new ConnectionManager(db, settings, redis);
|
|
connectionManager.registerPollingCallback();
|
|
|
|
const repoManager = new RepoManager(db, settings, redis, promClient, context);
|
|
await repoManager.validateIndexedReposHaveShards();
|
|
await repoManager.blockingPollLoop();
|
|
}
|