Skip to content

refactor: wait for triple store via compose healthcheck, drop startup sleep (#45) - #154

Draft
ashleycaselli wants to merge 1 commit into
mainfrom
refactor/service-dependency-remove-startup-wait-issue-45
Draft

refactor: wait for triple store via compose healthcheck, drop startup sleep (#45)#154
ashleycaselli wants to merge 1 commit into
mainfrom
refactor/service-dependency-remove-startup-wait-issue-45

Conversation

@ashleycaselli

Copy link
Copy Markdown
Member

Closes #45.

What & why

LocalNanopubLoader.init() blocked for a fixed INIT_WAIT_SECONDS (default 120s) at startup "to make sure the triple store is up" via a Thread.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 rdf4j service already defines a healthcheck, but the query service had no depends_on. This PR wires that up and removes the sleep:

  • docker-compose.yml: add depends_on: rdf4j: condition: service_healthy to query; drop the obsolete INIT_WAIT_SECONDS env comment.
  • LocalNanopubLoader: remove the fixed wait loop and the getWaitSeconds() / INIT_WAIT_SECONDS / DEFAULT_WAIT_SECONDS machinery.
  • LocalNanopubLoaderTest: drop the now-obsolete getWaitSeconds stub.

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 13 Thread.sleep() calls, only the LocalNanopubLoader startup 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 bounded MAX_RETRIES retry loops after failed triple-store writes.
  • JellyNanopubLoader circuit-breaker pauses (BREAKER_PAUSE_MS) and batch retry delay (RETRY_DELAY_JELLY) for a saturated/restarting RDF4J during operation.
  • JellyNanopubLoader Registry 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 by depends_on.

⚠️ Deployment note

The compose file in this repo is a reference/example. The deployment compose lives in the private nanopub-infrastructure repo (nanopub-query/docker-compose.yml), which I couldn't access. That file must get the same depends_on: rdf4j: condition: service_healthy addition 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.
  • Full compile + test-compile: clean.
  • docker-compose.yml parses and resolves query.depends_on = {rdf4j: {condition: service_healthy}}.

🤖 Generated with Claude Code

… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add services dependency in docker-compose.yml

1 participant