Skip to content

The watchdog is a package now, not a file in this repo - #80

Merged
ralyodio merged 1 commit into
mainfrom
worktree-use-watchdog-pkg
Sep 22, 2026
Merged

ralyodio merged 1 commit into
mainfrom
worktree-use-watchdog-pkg

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

Shipped here yesterday in #79 as apps/web/src/lib/db-watchdog.js. genrewatch and
watchnews both need the same thing for the same reason, so it is now
@profullstack/watchdog 0.2.0
instead of three copies.

Why a package rather than a copy

What is worth sharing is not the code, it is the reasoning:

  • the probe has to go through the same client the requests use, because a second
    connection is the one thing guaranteed to look healthy during this failure
  • the timeout has to be a race, not a driver option, because the symptom is a promise
    that never settles
  • Redis is allowed one more failure than the pool, because a healthy Redis is routinely
    unreachable while it reloads its snapshot (26s at 1.8GB, 124s at the 8.65GB that caused
    The live tick was storing every synced row in Redis, sixty times an hour #78)

A comment explaining that is worth nothing if it lives in one of three copies, and the
numbers drift apart the moment they are duplicated.

What changes here

const watchdogs = watchDependencies({
  postgres: () => healthcheck(),
  redis: () => connection.ping(),
});

watchDependencies takes probes rather than clients, so the package stays
zero-dependency and does not care that this repo is on bun:sql and ioredis. The
DB_WATCHDOG_* and REDIS_WATCHDOG_* knobs and their defaults live there now, so this
file no longer names any of them.

  • apps/web/src/lib/db-watchdog.js deleted
  • test/db-watchdog.test.js deleted, the module's 19 tests live in the package
  • @profullstack/watchdog added to apps/web/package.json, beside the other
    @profullstack app dependencies
  • net 38 lines lighter

Behaviour is unchanged: same probes, same timings, same one-extra-failure for Redis.

Testing

bun install resolves 0.2.0, bun build apps/web/src/main.js bundles clean (which is what
actually proves the new import resolves), biome check clean, and 39 pass / 0 fail across
config, nichedb-plays and odds-archive.

The package itself is 19 tests, zero dependencies, no build step.

Note

apps/worker/src/main.js is the alternate entry for splitting workers onto their own
service, and it has no watchdog. It is not the deployed shape (the default runs web+worker
in one container via apps/web), so I left it alone rather than widen this.

🤖 Generated with Claude Code

Shipped here yesterday as apps/web/src/lib/db-watchdog.js, and genrewatch and
watchnews both need the same thing for the same reason, so it is
@profullstack/watchdog 0.2.0 instead of three copies.

What moved is not really the code, it is the reasoning. Why the probe has to go
through the SAME client the requests use, why the timeout has to be a race rather
than a driver option, and why Redis is allowed one more failure than the pool
because a healthy Redis is routinely unreachable while it reloads its snapshot.
A comment explaining that is worth nothing if it only exists in one of three
copies, and the numbers drift apart the moment they are duplicated.

`watchDependencies` takes probes rather than clients, so the package stays
zero-dependency and does not care that this repo is on bun:sql and ioredis. The
DB_WATCHDOG and REDIS_WATCHDOG knobs and their defaults live there too, so this
file no longer names any of them.

Net 38 lines lighter here, and the module's own tests moved to the package.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ralyodio
ralyodio merged commit ca892f8 into main Sep 22, 2026
2 checks passed
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.

1 participant