Skip to content

12.36.0

Choose a tag to compare

@timgit timgit released this 02 Oct 20:51
· 218 commits to master since this release

Schema version: 44. A migration runs on upgrade; see Upgrading.

  • OpenTelemetry tracing and metrics, following the messaging semantic conventions.
  • With persistQueueStats on, the monitor records how long jobs waited and ran, as histograms you can read percentiles from.
  • Every pg-boss instance records itself in the database, and getInstances() lists them.
  • Jobs blocked by a flow parent are counted as blockedCount, and readyCount no longer includes them.

Wait and run times

Each counted monitor pass now records, for the jobs that finished in its window, waitBins (from when a job could first start until a worker started it) and runBins, each a histogram of 48 log-spaced bins. A deferred job or a retry in its backoff is not counted as waiting. readyOldestSeconds is how long the oldest ready job had waited at the pass, so it keeps rising on a queue whose workers have stopped.

getQueueStats() returns them on every snapshot, and getQueue() and getQueues() return the latest pass. Additionally, you can calculate percentiles as well:

const series = await boss.getQueueStats('email-send', { maxDataPoints: 300, percentiles: [50, 95] })
// each snapshot: percentiles: [{ p: 50, waitSeconds: 0.281, runSeconds: 1.254 }, { p: 95, waitSeconds: 0.616, runSeconds: 2.397 }]

retry() and resume() now move a job's startAfter up to the time of the call, as does a flow parent releasing its child, so the wait counts from when the job could run again.

Instances

Each PgBoss object now keeps a row in a new instance table and useful runtime information, such as host, pid, CPU, memory, version, and constructor configuration (NOT connection settings or credentials). getInstances() lists them. Use the new instanceName prop to name your instance, and instanceHeartbeatSeconds if you want to change the default heartbeat from 30s. Short-lived processes such as serverless functions should set registerInstance: false, or each invocation reads as a crash if you don't use stop().

Each call to start() will assign a random id to your instance. Unless you set application_name yourself, connections on a pool pg-boss creates are now named pgboss: plus the first 8 characters of the instance id, so pg_stat_activity joins to the registry. See Instance table.

Blocked jobs

A job waiting on a flow() parent is no longer counted as ready, since no worker can fetch it. getQueue() and getQueues() return it as blockedCount, so queuedCount is deferredCount + blockedCount + readyCount. It is a live count only; queue_stats keeps no history of it.

OpenTelemetry

pg-boss creates spans and metrics through @opentelemetry/api. Without a registered SDK they are
no-ops.

  • Spans: producer spans for send(), insert(), upsert(), flow() and publish(); a process {queue} consumer span around each worker batch, so spans in the handler nest under it; receive and settle spans for fetch(), complete(), fail(), cancel() and deleteJob().
  • Trace propagation, opt-in with propagateContext: true, stores the trace context on the job (a new trace_context column) so a worker continues the producer's trace, across retries, dead lettering and redrive.
  • Metrics: sent, consumed, operation and process duration, and a pgboss.queue.jobs gauge per queue and state, read from the queue cache with no extra queries.

The openTelemetry constructor option takes enabled, propagateContext, propagator, tracerProvider and meterProvider. See OpenTelemetry. Thanks to @kibertoad for #939, closing #637.

Upgrading

Schema 44 adds the instance table, blocked_count, wait_bins, run_bins and ready_oldest_seconds to queue, the last three to queue_stats, and trace_context to job.

@opentelemetry/api is a new peer dependency (^1.9.0).

An application already running an OpenTelemetry SDK receives pg-boss spans and metrics on upgrade. openTelemetry: { enabled: false } turns them off.

readyCount no longer includes blocked jobs for queues that use flows. History before the upgrade still includes blocked jobs.

If you don't set application_name, it changes from pgboss to pgboss:<id>. A name you already set is kept, as are a db adapter's connections and those of an instance with registerInstance: false.

PRs

Full Changelog: 12.35.1...12.36.0