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

Method runDeferredSynthesis

src/index.ts:2015–2042  ·  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

2013 * here is logged and tried again after the interval, as lock contention is.
2014 */
2015 private async runDeferredSynthesis(): Promise<void> {
2016 const retryLater = (): void => {
2017 if (!this.db.isOpen()) return;
2018 this.armDeferredSynthesis(parseSynthMinIntervalEnv(process.env.CODEGRAPH_SYNTH_MIN_INTERVAL_MS) ?? 1000);
2019 };
2020 try {
2021 await this.indexMutex.withLock(async () => {
2022 if (this.queries.getMetadata('synthesis_pending') !== '1') return;
2023 try {
2024 this.fileLock.acquire();
2025 } catch {
2026 retryLater();
2027 return;
2028 }
2029 try {
2030 // A rebuild may have replaced the file meanwhile, as sync checks.
2031 this.reopenReplacedDatabase();
2032 if (this.queries.getMetadata('synthesis_pending') !== '1') return;
2033 await this.synthesizeWithWalDeferred();
2034 } finally {
2035 this.fileLock.release();
2036 }
2037 });
2038 } catch (err) {
2039 logWarn(`Put-off synthesis failed, trying again after the interval: ${err instanceof Error ? err.message : String(err)}`);
2040 retryLater();
2041 }
2042 }
2043
2044 /**
2045 * 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