GoodJob.PubSub (good_job v1.0.0)

Copy Markdown View Source

Broadcasts job events to Phoenix.PubSub for real-time LiveView updates.

This allows LiveViews to subscribe to job events and update automatically when jobs are created, updated, or completed.

Note: This module is optional and requires Phoenix to be available. If Phoenix is not available, all functions will gracefully no-op. The core GoodJob library works perfectly fine without Phoenix.

Summary

Functions

Broadcasts a job event to all subscribers.

Subscribes to job events.

Functions

broadcast(event, job_id)

Broadcasts a job event to all subscribers.

Events:

  • :job_created - A new job was enqueued
  • :job_updated - A job's state changed (e.g., started running)
  • :job_completed - A job finished (succeeded or discarded)
  • :job_deleted - A job was deleted
  • :job_retried - A job was retried
  • :job_discarded - A job was discarded

Returns :ok if broadcast succeeded, :noop if Phoenix is not available.

subscribe(pubsub_server \\ nil)

Subscribes to job events.

Returns the topic name for use in LiveView subscriptions, or nil if Phoenix is not available.