PhoenixKitStaff.PubSub (PhoenixKitStaff v0.2.0)

Copy Markdown View Source

Real-time updates for the staff module, backed by PhoenixKit.PubSub.Manager (the shared in-process PubSub server).

Topics

  • "staff:departments" — any department mutation
  • "staff:teams" — any team mutation
  • "staff:people" — any person mutation
  • "staff:department:<uuid>" — a single department
  • "staff:team:<uuid>" — a single team
  • "staff:person:<uuid>" — a single person

Events

Messages are {:staff, event_atom, payload_map} tuples. Payload always includes :uuid at a minimum. Subscribers should pattern-match on the event atom in handle_info/2.

Summary

Types

Department/team/person broadcast event atom.

PubSub topic name.

Functions

Broadcasts a department event to the departments topic and the department's own topic.

Broadcasts a person event to the people topic and the person's own topic.

Broadcasts a team event to the teams, team, and (if present) parent-department topics.

Broadcasts a team-membership event to the teams, team, people, and person topics.

Subscribes the calling process to the given PubSub topic.

Topic scoped to a single department.

Topic for all department mutations.

Topic for all person mutations.

Topic scoped to a single person.

Topic scoped to a single team.

Topic for all team mutations.

Types

event()

@type event() :: atom()

Department/team/person broadcast event atom.

topic()

@type topic() :: String.t()

PubSub topic name.

Functions

broadcast_department(event, payload)

@spec broadcast_department(event(), %{
  :uuid => UUIDv7.t() | String.t(),
  optional(any()) => any()
}) ::
  :ok

Broadcasts a department event to the departments topic and the department's own topic.

broadcast_person(event, payload)

@spec broadcast_person(event(), %{
  :uuid => UUIDv7.t() | String.t(),
  optional(any()) => any()
}) :: :ok

Broadcasts a person event to the people topic and the person's own topic.

broadcast_team(event, payload)

@spec broadcast_team(event(), %{
  :uuid => UUIDv7.t() | String.t(),
  optional(any()) => any()
}) :: :ok

Broadcasts a team event to the teams, team, and (if present) parent-department topics.

broadcast_team_membership(event, payload)

@spec broadcast_team_membership(event(), %{
  :team_uuid => UUIDv7.t() | String.t(),
  :staff_person_uuid => UUIDv7.t() | String.t(),
  optional(any()) => any()
}) :: :ok

Broadcasts a team-membership event to the teams, team, people, and person topics.

subscribe(topic)

@spec subscribe(topic()) :: :ok | {:error, term()}

Subscribes the calling process to the given PubSub topic.

topic_department(uuid)

@spec topic_department(UUIDv7.t() | String.t()) :: topic()

Topic scoped to a single department.

topic_departments()

@spec topic_departments() :: topic()

Topic for all department mutations.

topic_people()

@spec topic_people() :: topic()

Topic for all person mutations.

topic_person(uuid)

@spec topic_person(UUIDv7.t() | String.t()) :: topic()

Topic scoped to a single person.

topic_team(uuid)

@spec topic_team(UUIDv7.t() | String.t()) :: topic()

Topic scoped to a single team.

topic_teams()

@spec topic_teams() :: topic()

Topic for all team mutations.