refactor: wait for triple store via compose healthcheck, drop startup sleep (#45) - #154
Draft
ashleycaselli wants to merge 1 commit into
Draft
Conversation
… sleep (#45) LocalNanopubLoader.init() blocked for a fixed INIT_WAIT_SECONDS (default 120s) at startup "to make sure the triple store is up". This blind sleep is both wasteful (when rdf4j is ready in seconds) and fragile (when it takes longer), and duplicates ordering that Docker Compose can express directly. Add `depends_on: rdf4j: condition: service_healthy` to the query service (rdf4j already defines a healthcheck) so the container only starts once the triple store is healthy, and remove the now-redundant fixed wait loop plus its getWaitSeconds()/INIT_WAIT_SECONDS/DEFAULT_WAIT_SECONDS config. The remaining Thread.sleep() calls (NanopubLoader backoff, Jelly circuit breaker, Registry metadata retry) are runtime resilience/backoff logic, not service-availability waits, and are intentionally left in place. Co-Authored-By: Claude Opus 4.8 <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 #45.
What & why
LocalNanopubLoader.init()blocked for a fixedINIT_WAIT_SECONDS(default 120s) at startup "to make sure the triple store is up" via aThread.sleep()loop. That blind wait is both wasteful (when rdf4j is ready in seconds) and fragile (fails if it takes longer), and it duplicates ordering that Docker Compose expresses directly.The
rdf4jservice already defines ahealthcheck, but thequeryservice had nodepends_on. This PR wires that up and removes the sleep:docker-compose.yml: adddepends_on: rdf4j: condition: service_healthytoquery; drop the obsoleteINIT_WAIT_SECONDSenv comment.LocalNanopubLoader: remove the fixed wait loop and thegetWaitSeconds()/INIT_WAIT_SECONDS/DEFAULT_WAIT_SECONDSmachinery.LocalNanopubLoaderTest: drop the now-obsoletegetWaitSecondsstub.Scope: only one sleep was a service-availability wait
The issue says "some classes use
Thread.sleep()to wait for a service… remove all no-longer-needed calls." After auditing all 13Thread.sleep()calls, only theLocalNanopubLoaderstartup wait fits that description. The rest are deliberately kept because they are runtime resilience/backoff, not startup service-availability waits:NanopubLoader(×8): exponential backoff (computeBackoffMillis) inside boundedMAX_RETRIESretry loops after failed triple-store writes.JellyNanopubLoadercircuit-breaker pauses (BREAKER_PAUSE_MS) and batch retry delay (RETRY_DELAY_JELLY) for a saturated/restarting RDF4J during operation.JellyNanopubLoaderRegistry metadata retry (RETRY_DELAY_METADATA): a bounded retry against the external Registry (REGISTRY_FIXED_URL), which is not a Compose service and cannot be covered bydepends_on.The compose file in this repo is a reference/example. The deployment compose lives in the private
nanopub-infrastructurerepo (nanopub-query/docker-compose.yml), which I couldn't access. That file must get the samedepends_on: rdf4j: condition: service_healthyaddition for the fix to take effect in production — otherwise the app starts without the sleep and without the ordering guarantee. Please mirror this change there.Testing
LocalNanopubLoaderTest: 5/5 passing.compile+test-compile: clean.docker-compose.ymlparses and resolvesquery.depends_on = {rdf4j: {condition: service_healthy}}.🤖 Generated with Claude Code