Feature: di.heartbeat#100
Open
Olly99999 wants to merge 7 commits into
Open
Conversation
…r dep example found during manual test with a real di.timer
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.
di.heartbeat
Extracts TorQ's code/common/heartbeat.q into a standalone kdb-x module (Tier-1, no hard module dependencies).
What it does. Lets a process publish a periodic heartbeat over pub/sub, and lets a monitoring process collect those beats and detect when a process has gone silent — escalating it to warning then error after configurable grace periods. This catches a process that is alive but stuck (blocked, deadlocked, GC-thrashing), which a plain "is the connection open?" check cannot.
Two sides:
Publish — publishheartbeat emits a one-row beat (type, name, counter, pid/host/port) on a timer.
Monitor — storeheartbeat records incoming beats (latest per process, clearing prior alerts); checkheartbeat flags any that have aged past their grace period and fires onwarning/onerror callbacks. Alerts are edge-triggered (fire once per transition) and re-arm automatically when a process beats again.
Dependency injection. All runtime dependencies are injected via init[config;deps] as dictionaries of functions, per the injectable-dependency guidance:
log, timer, pubsub — always required
servers, handlers — required only when running as a monitor (subenabled)
Missing required deps error immediately with a clear message rather than silently degrading. The module keeps its own clock (cp/setcp) so it doesn't depend on the timer exposing a getter, and overriding it makes the staleness logic deterministic for tests.
Conventions. No \d namespaces — module-local state via .z.m. No direct .z.* handler assignment — the .z.pc cleanup goes through the injected handlers dependency. Config via dictionary, not @[value;…]. FinSpace code stripped (none present).
Files: init.q (entry point + exports + version), heartbeat.q (implementation), deps.q (empty — all deps injected), heartbeat.md (docs), test.csv (38 k4unit tests, all passing).
Status. Unit-tested (38/38) and manually integration-tested against the real di.timer and di.pubsub — verified beats publishing on schedule and a killed publisher being escalated to error end-to-end. Known follow-ups: init is not yet idempotent (re-running collides on timer job ids); the servers/handlers auto-discovery path awaits the real di.servers/di.handlers modules.