MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / runDeferredSynthesis

Method runDeferredSynthesis

src/index.ts:2032–2059  ·  view source on GitHub ↗

* The put-off synthesis, under the locks a sync holds. Nothing to do when a * sync ran it meanwhile. When the file lock is taken by another process, * try again after the interval; `synthesis_pending` stays set throughout. * * It runs from a timer, so nothing above it catches a failure,

()

Source from the content-addressed store, hash-verified

2030 * here is logged and tried again after the interval, as lock contention is.
2031 */
2032 private async runDeferredSynthesis(): Promise<void> {
2033 const retryLater = (): void => {
2034 if (!this.db.isOpen()) return;
2035 this.armDeferredSynthesis(parseSynthMinIntervalEnv(process.env.CODEGRAPH_SYNTH_MIN_INTERVAL_MS) ?? 1000);
2036 };
2037 try {
2038 await this.indexMutex.withLock(async () => {
2039 if (this.queries.getMetadata('synthesis_pending') !== '1') return;
2040 try {
2041 this.fileLock.acquire();
2042 } catch {
2043 retryLater();
2044 return;
2045 }
2046 try {
2047 // A rebuild may have replaced the file meanwhile, as sync checks.
2048 this.reopenReplacedDatabase();
2049 if (this.queries.getMetadata('synthesis_pending') !== '1') return;
2050 await this.synthesizeWithWalDeferred();
2051 } finally {
2052 this.fileLock.release();
2053 }
2054 });
2055 } catch (err) {
2056 logWarn(`Put-off synthesis failed, trying again after the interval: ${err instanceof Error ? err.message : String(err)}`);
2057 retryLater();
2058 }
2059 }
2060
2061 /**
2062 * The rebuild, with the WAL handling a sync gives it (#1231, #1248): a whole

Callers 1

armDeferredSynthesisMethod · 0.95

Calls 7

logWarnFunction · 0.90
getMetadataMethod · 0.80
releaseMethod · 0.65
withLockMethod · 0.45
acquireMethod · 0.45

Tested by

no test coverage detected