Repository navigation
Conversation
…ributionScheduler The boot block started a PayoutDriftDetector before the role checks and a second one under roleConfig.payoutDrift, so api replicas ran drift detection and batch/all ran it twice; the first was never stopped. Move the batch services into startBackgroundServices(roleConfig, factories), which starts each at most once under its own flag and returns its stop function. Session compaction gets its own flag instead of reusing auditPurge. Nothing ever started the DistributionScheduler, so scheduled_distributions rows stayed scheduled forever. Add a distributionScheduler role flag and createDistributionSchedulerRuntime: catch-up once at boot, then process pending and scheduled distributions on chained setTimeout ticks that never overlap; stop() cancels the timer and awaits the in-flight tick, and shutdown() awaits it before closing the pool. Also import the StellarTransactionVerifierImpl the reconciliation start already used. Closes RevoraOrg#1297 Closes RevoraOrg#1298 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1297
Closes #1298
Both issues change the same worker boot block in
src/index.ts, so they're fixed together: #1298 extracts it, and #1297 adds the scheduler to the extracted version.#1298: services started twice / in the wrong role
PayoutDriftDetectorthat started before the role checks and was never stopped.src/services/backgroundServices.ts:startBackgroundServices(roleConfig, factories)starts each batch service (audit purge, session compaction, payout drift, reconciliation, distribution scheduler) at most once, only under its own role flag, and returns a stop function for each.index.tspasses real factories, and tests pass spies.sessionCompactionflag instead of reusingauditPurge. It's on forbatch/alland off forapi, so behaviour is the same as before.#1297: DistributionScheduler never started
distributionSchedulerrole flag: on forbatch/all, off forapi.createDistributionSchedulerRuntime({ engine, revenueReportRepo, scheduledDistributionRepo, intervalMs, metrics })indistributionScheduler.ts:catchUpMissedWindowsonce at boot, thenprocessPendingDistributions+processScheduledDistributionseach ticksetTimeout(the next is scheduled only after the previous finishes), so they never overlapstop()cancels the pending timer and resolves after the in-flight tick finishesDISTRIBUTION_SCHEDULER_INTERVAL_MS, else 60 sshutdown()now awaits the background stop functions beforeclosePool(), so an in-flight tick isn't cut off.createApp, so the snapshot-backed balance provider is now a small exportedcreateSnapshotBalanceProvider().createAppand the worker build the sameDistributionEngine.Extra fix:
index.tsusedStellarTransactionVerifierImplwithout importing it (tscTS2304 onmaster), which would throw whenbatch/allstarts the reconciliation scheduler. Added the import.Tests
src/__tests__/backgroundServices.test.ts(new):apistarts zero servicesbatchandallstart each exactly once, including exactly one drift detectorindex.tsthat the drift detector is only created throughstartBackgroundServices. Onmasterthere are two.distributionScheduler.test.tsruntime block, with fake timers:stop()cancels the timerstop()awaits the in-flight tickworkerRole.test.ts: the new flags across the role matrix.Results:
backgroundServices+workerRole: 34/34 pass.distributionScheduler.test.tsfile has 10 holiday-calendar tests that already fail onmaster. Those are unchanged.tsc --noEmitreports no new errors; the TS2304 above is gone. ESLint is clean on the new files.🤖 Generated with Claude Code