iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Capture both queue-level errors and each individual processing attempt, then use a stable media-work ID to join attempts to metered resource usage. With pg-boss, attach an error listener before starting the queue; for cost attribution, combine attempt telemetry with your own billing data. pg-boss and OpenTelemetry provide observability signals, not media-cost calculations.
What you need to capture
A scheduled job is not necessarily a single execution. pg-boss is a Node.js job queue backed by PostgreSQL that supports scheduled work, including cron scheduling. Its documented at-least-once delivery means a job may run more than once, so a handler must tolerate duplicate execution. A handler error ordinarily triggers a retry and may eventually leave the job failed. See the pg-boss introduction.
For useful troubleshooting and cost estimates, preserve a record for every attempt, not just the final job status. Use one stable logical work ID for the media operation across retries, and capture the queue job ID separately: the logical ID groups executions, while the job ID identifies queue work.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitches- Logical media-work ID and, where useful, the asset or pipeline-stage ID.
- Queue job ID and queue name.
- Attempt number or retry count.
- Attempt start and end timestamps, or processing duration.
- Outcome and a classified error type.
- Measured resource usage needed for billing, such as provider-reported processing units or other metered consumption.
- Trace context, if configured, to connect submission and processing activity.
Capture pg-boss errors before starting the worker
Queue-level errors are distinct from failures thrown by an individual handler. pg-boss documents that internal errors can occur during scheduling and maintenance as well as while jobs are being processed. Its Events documentation says that adding an error listener is “strongly encouraged” because of Node.js’s default behavior for an unhandled error event. Register the listener before start().
#1 Best Overall
const boss = new PgBoss(connectionString);
boss.on("error", (error) => {
logger.error({
event: "pgboss.error",
error: {
name: error.name,
message: error.message
}
}, "pg-boss emitted an error");
// Send the event to your established alerting or error pipeline.
});
await boss.start();
This illustrative pattern assumes PgBoss and logger are already configured for your application. Adapt the logged fields to your error pipeline. Avoid logging secrets, connection details, or sensitive media payloads; preserve only metadata that helps diagnose the failure. Consult the pg-boss Events documentation for the event behavior.
Record each processing attempt
pg-boss documents OpenTelemetry process spans, retry-count and error-type attributes, and a processing-duration metric. It also supports optional trace-context propagation from job submission to processing, including retries. These capabilities provide useful queue and execution context, but the application still needs to associate telemetry with its stable media-work ID. See pg-boss OpenTelemetry support.
Rank #2
OpenTelemetry defines messaging.process.duration as a histogram measured in seconds. Its messaging conventions recommend predictable, low-cardinality values for error.type; avoid putting unique IDs or arbitrary error messages into that classification. See OpenTelemetry’s messaging client metric conventions.
A practical attempt record can be structured around fields like these, mapped to your database or telemetry system:
Rank #3
{
"work_id": "stable-logical-media-work-id",
"asset_id": "media-asset-id",
"queue": "media-processing",
"job_id": "queue-job-id",
"retry_count": 1,
"attempt_started_at": "timestamp",
"attempt_ended_at": "timestamp",
"outcome": "error",
"error_type": "transient_provider_error",
"resource_usage": {
"provider_units": 0
},
"trace_id": "trace-id"
}
The example names are application-level fields, not a claim that pg-boss emits this exact record. Map documented span attributes and metrics into your telemetry store, and add the work and asset identifiers where your application can reliably supply them. Treat timestamp values and resource usage as recorded by your system or provider, not as values inferred from queue retry counts.
Join attempts to usage and estimate retry cost
To estimate the cost of retries, group attempt records by logical work ID, sum the relevant measured usage across those attempts, then apply the rates from your own provider or internal billing records. A retry count or processing duration can help identify work worth investigating, but neither provides a dollar amount by itself. Duration is not a substitute for metered usage when a provider bills on another basis.
Rank #4
- Store each attempt with the stable work ID and enough identifiers to join it to the media asset, pipeline stage, or provider usage record.
- Retrieve measured consumption for each attempt from the application’s resource records or the relevant provider’s billing data.
- Group all attempts for the same logical work, including successful and failed attempts that incurred usage.
- Apply the rate that matches the applicable service, billing period, and geography.
- Label the result as an estimate when usage or rates are incomplete; distinguish it from a directly metered charge.
Keep the calculation explainable: retain the attempt-level inputs, rate source, billing period, and relevant geography alongside the estimate. If the underlying usage and rate data are unavailable, report the attempts and duration without assigning an exact monetary amount. pg-boss and OpenTelemetry do not provide media-processing prices or an off-the-shelf retry-cost model.
Design for duplicate execution and operational limits
Because pg-boss uses at-least-once delivery, make handlers idempotent where possible or otherwise safe to repeat. For example, ensure that recording a completed stage or updating a work status does not accidentally duplicate application-side effects when the same work is processed again. Do not treat one scheduled job record as proof of one media execution.
Operational capacity also matters: the pg-boss introduction notes that each instance maintains its own database connection pool, and PostgreSQL’s connection limit constrains how many instances can run. Account for that when sizing workers and retain enough attempt telemetry to support the troubleshooting and billing window your team needs. Queue configuration and retention choices are application-specific.
What this instrumentation can—and cannot—tell you
Queue events, spans, retry counts, classified errors, and processing-duration metrics help locate failures and identify repeated or potentially expensive work. Stable work IDs make it possible to connect that activity to application records. A defensible cost estimate still depends on measured resource usage and the rates that apply to your account; telemetry alone does not establish a provider charge. OpenTelemetry’s semantic conventions define shared meanings for telemetry signals, not billing rules.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Free tools Windows power users keep installed
One-click scans. No signup required.

