LightningWeb.WorkerPresence (Lightning v2.14.11-pre1)

View Source

Handles worker presence tracking for connected workers.

This module leverages Phoenix.Presence to track worker connections, allowing the system to dynamically calculate available worker capacity.

Summary

Functions

Callback implementation for Phoenix.Presence.fetch/2.

Callback implementation for Phoenix.Presence.list/1.

Calculates the total worker capacity across all connected workers.

Callback implementation for Phoenix.Presence.track/3.

Tracks a worker's presence when they connect.

Callback implementation for Phoenix.Presence.untrack/2.

Functions

child_spec(opts)

fetch(topic, presences)

Callback implementation for Phoenix.Presence.fetch/2.

fetchers_pids()

get_by_key(topic, key)

Callback implementation for Phoenix.Presence.get_by_key/2.

list(topic)

Callback implementation for Phoenix.Presence.list/1.

total_worker_capacity()

Calculates the total worker capacity across all connected workers.

Returns the sum of all worker capacities currently tracked in Presence.

Examples

iex> LightningWeb.WorkerPresence.total_worker_capacity()
10

track(socket, key, meta)

Callback implementation for Phoenix.Presence.track/3.

track(pid, topic, key, meta)

Callback implementation for Phoenix.Presence.track/4.

track_worker(pid, worker_id, capacity)

Tracks a worker's presence when they connect.

Parameters

  • pid: The process identifier for the worker's channel.
  • worker_id: A unique identifier for the worker.
  • capacity: The number of concurrent runs this worker can handle.

Examples

iex> LightningWeb.WorkerPresence.track_worker(self(), "worker-123", 5)
{:ok, _ref}

untrack(socket, key)

Callback implementation for Phoenix.Presence.untrack/2.

untrack(pid, topic, key)

Callback implementation for Phoenix.Presence.untrack/3.

update(socket, key, meta)

Callback implementation for Phoenix.Presence.update/3.

update(pid, topic, key, meta)

Callback implementation for Phoenix.Presence.update/4.