HawkEx.Events (hawk_ex v0.1.0)

Copy Markdown View Source

Broadcasts HawkEx business events through the host application's PubSub.

Events are only broadcast when config :hawk_ex, pubsub: is set. Without it, emit/2 and subscribe/0 are silent no-ops so the library can be used without Phoenix PubSub.

Topic

All events are broadcast on a single topic: "hawk_ex:events".

Subscribing

HawkEx.Events.subscribe()

# Then handle in a GenServer or LiveView:
def handle_info({HawkEx.Events, event, payload}, state) do
  ...
end

Event names

String dot-notation:

"subscription.created"
"subscription.canceled"
"subscription.plan_changed"

Payload

Each event carries a map with at minimum:

%{account_id: uuid, ...event-specific fields}

Summary

Functions

Broadcasts an event to all subscribers.

Subscribes the calling process to all HawkEx events.

The PubSub topic used for all HawkEx events.

Functions

emit(event_name, payload)

Broadcasts an event to all subscribers.

The message format is {HawkEx.Events, event_name, payload}. Returns :ok when PubSub is not configured.

subscribe()

Subscribes the calling process to all HawkEx events.

Returns :ok when PubSub is not configured.

topic()

The PubSub topic used for all HawkEx events.