Skip to content

Replace hardcoded sleep with database readiness check in engine entrypoint #91

@KaranJagtiani

Description

@KaranJagtiani

The engine entrypoint script (deployment/engine/entrypoint.sh) uses a hardcoded sleep 30 to wait for the database before starting. This is unreliable — the database may not be ready after 30 seconds, or it may be ready much sooner, wasting startup time.

Scope

  • Infra (deployment/engine/entrypoint.sh):
    • Replace sleep 30 with a loop that checks database connectivity before proceeding.
    • Use pg_isready (available in the container) or a lightweight Python check against the DATABASE_URL environment variable.
    • Add a configurable timeout (e.g., DB_WAIT_TIMEOUT, default 60 seconds) with a clear failure message if the database isn't reachable in time.
    • Add a similar readiness check for Redis using redis-cli ping or equivalent if the Redis client is available.

Acceptance criteria

  • Engine waits for the database to be reachable before starting, rather than sleeping for a fixed duration.
  • If the database is not reachable within the timeout, the script exits with a non-zero code and a clear error message.
  • The timeout is configurable via an environment variable (DB_WAIT_TIMEOUT).
  • Startup is faster when the database is already available (no unnecessary wait).
  • No regressions to normal engine startup behavior.

How to test manually

  1. Run the database and engine containers locally (see deployment/local.docker-compose.yaml).
  2. Start the engine with the database already running — verify it starts without waiting the full timeout.
  3. Start the engine before the database — verify it waits and starts successfully once the database comes up.
  4. Start the engine with the database down — verify it exits with a clear error after the timeout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions