Class QAlerts

java.lang.Object
com.kingsrook.qqq.backend.core.alerts.QAlerts

public final class QAlerts extends Object
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 Details

    • raise

      public static void raise(AlertSignal signal)
      Raise (or refresh) an alert. Idempotent on (type, dedupKey). Deferred until commit when QContext has a transaction.
    • raise

      public static void raise(AlertSignal signal, QBackendTransaction transaction)
      Raise (or refresh) an alert after the given transaction commits (or now, when transaction is null and QContext has none).
    • resolve

      public static void resolve(String alertTypeName, String dedupKey, String note)
      Resolve an open alert (a no-op if it is not open).
    • resolve

      public static void resolve(AlertResolution resolution, QBackendTransaction transaction)
      Resolve an open alert after the given transaction commits (or now).
    • heartbeat

      public static void heartbeat(String heartbeatKey)
      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

      public static void notify(NotificationSignal signal)
      Send a user notification ("tell these people this"). Deferred until commit when QContext has a transaction. title and audience are required.
    • notify

      public static void notify(NotificationSignal signal, QBackendTransaction transaction)
      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.