HawkEye.Oban (hawk_eye v0.1.0)

Copy Markdown View Source

Reports Oban jobs to HawkEye heartbeat monitors, with no changes to your workers.

Create a heartbeat monitor in HawkEye for each scheduled worker, with its period set to how often the job runs (and a little grace time). Then map each worker to its monitor's ping token or ping URL:

# config/runtime.exs
if config_env() == :prod do
  config :hawk_eye,
    oban: [
      workers: %{
        MyApp.Workers.NightlyReport => System.get_env("HAWKEYE_NIGHTLY_REPORT"),
        MyApp.Workers.SyncInvoices => System.get_env("HAWKEYE_SYNC_INVOICES")
      }
    ]
end

The handler is attached when the :hawk_eye application starts. Workers that aren't listed are ignored. A worker whose token is missing (for example an unset environment variable) is skipped with a warning, so a configuration mistake never stops your application from starting.

What gets reported

Job outcomeReported to HawkEye
Succeeded (:ok, {:ok, _})success
Failed, will be retriednothing, unless fail_on: :every_attempt
Failed on its last attemptfailure, with the error
Discarded by the worker ({:discard, _})failure
Cancelled ({:cancel, _})nothing, unless cancelled: says otherwise
Snoozednothing (the job runs again later)

A job that never runs at all sends nothing, and HawkEye alerts when the monitor's deadline passes. That is what a heartbeat is for: it catches a stopped scheduler, a crashed node or a paused queue, which nothing inside your application can report.

Heartbeats suit scheduled workers. Don't list a worker that runs thousands of times a minute: HawkEye accepts about one ping a second per monitor.

Options

  • :workers - a map (or keyword list) of worker module, or worker name as a string, to a ping token or ping URL. Required.
  • :fail_on - :final_attempt (default) reports a failure only once Oban stops retrying; :every_attempt reports every failed attempt.
  • :cancelled - what a cancelled job reports: :ignore (default), :success or :fail.
  • :include_error - true (default) sends the error message with a failure, so you can read it in HawkEye and in the alert. false sends only the worker name and attempt number. Turn it off if your error messages may contain personal or secret data.
  • :include_duration - true (default) sends how long a successful job took.

Summary

Functions

Attaches the telemetry handler with these options, replacing any earlier configuration.

Detaches the telemetry handler.

Functions

attach(opts)

@spec attach(keyword()) :: :ok | {:error, term()}

Attaches the telemetry handler with these options, replacing any earlier configuration.

Called for you at startup when config :hawk_eye, oban: [...] is set. Call it yourself only if you build the options in code.

detach()

@spec detach() :: :ok

Detaches the telemetry handler.