Class QAlerts
java.lang.Object
com.kingsrook.qqq.backend.core.alerts.QAlerts
The producer API for alerts ("manage by exception"). Any qbit or app can
call raise, resolve and heartbeat (and notify, for user notifications); with no alerts implementation installed
these go to LoggingAlertSink, so producers need nothing beyond core.
Guarantees (the same promises the ESB makes for publishing):
- never throws into the caller and never blocks it: a failure is logged and
counted (getProducerFailureCount).
- transaction-aware: when given a transaction (or when QContext has one),
the call is deferred with addAfterCommitCallback, and dropped on rollback,
so an alert never describes a write that did not happen.
- an unknown alert type name is passed on (with a rate-limited warning), so
a typo never loses a signal.
Example:
QAlerts.raise(new AlertSignal("cdn.purge.dead")
.withDedupKey("provider:" + providerId)
.withTitle("3 CDN purges failed after retries")
.withRecordRefs(AlertRecordRef.of("cdn_purge_request", ids)));
QAlerts.resolve("cdn.purge.dead", "provider:" + providerId, "A later purge succeeded");
QAlerts.heartbeat("backups.job.nightly-db");
-
Method Summary
Modifier and TypeMethodDescriptionstatic longHow many producer calls have failed (bad input, a sink that threw, a sink that could not load) since startup.static voidDead-man's switch: "I ran".static voidnotify(NotificationSignal signal) Send a user notification ("tell these people this").static voidnotify(NotificationSignal signal, QBackendTransaction transaction) Send a user notification after the given transaction commits (or now, when transaction is null and QContext has none).static voidraise(AlertSignal signal) Raise (or refresh) an alert.static voidraise(AlertSignal signal, QBackendTransaction transaction) Raise (or refresh) an alert after the given transaction commits (or now, when transaction is null and QContext has none).static voidresolve(AlertResolution resolution, QBackendTransaction transaction) Resolve an open alert after the given transaction commits (or now).static voidResolve an open alert (a no-op if it is not open).
-
Method Details
-
raise
Raise (or refresh) an alert. Idempotent on (type, dedupKey). Deferred until commit when QContext has a transaction. -
raise
Raise (or refresh) an alert after the given transaction commits (or now, when transaction is null and QContext has none). -
resolve
-
resolve
Resolve an open alert after the given transaction commits (or now). -
heartbeat
Dead-man's switch: "I ran". A heartbeat monitor raises when beats stop. Not deferred to a commit - a beat is about the code running, not data. -
notify
Send a user notification ("tell these people this"). Deferred until commit when QContext has a transaction. title and audience are required. -
notify
Send a user notification after the given transaction commits (or now, when transaction is null and QContext has none). Defaults occurredAt to now, severity to INFO and category to SYSTEM. -
getProducerFailureCount
public static long getProducerFailureCount()How many producer calls have failed (bad input, a sink that threw, a sink that could not load) since startup.
-