WeaviateEx.Client.State (WeaviateEx v0.7.4)

View Source

Client lifecycle state tracking.

Tracks the state of a client connection including:

  • Connection status
  • Request and error counts
  • Timestamps for lifecycle events

Example

state = State.new()
|> State.connected()
|> State.record_request()
|> State.record_request()

IO.puts("Request count: #{state.request_count}")

Summary

Functions

Transition to closed status.

Transition to connected status.

Transition to disconnected status with reason.

Create new client state.

Record an error.

Record a successful request.

Types

status()

@type status() :: :initializing | :connected | :disconnected | :closed

t()

@type t() :: %WeaviateEx.Client.State{
  created_at: DateTime.t(),
  error_count: non_neg_integer(),
  last_error: term() | nil,
  last_used_at: DateTime.t() | nil,
  request_count: non_neg_integer(),
  status: status()
}

Functions

closed(state)

@spec closed(t()) :: t()

Transition to closed status.

Example

state = State.connected(state) |> State.closed()

connected(state)

@spec connected(t()) :: t()

Transition to connected status.

Example

state = State.new() |> State.connected()

disconnected(state, reason)

@spec disconnected(t(), reason :: term()) :: t()

Transition to disconnected status with reason.

Example

state = State.connected(state) |> State.disconnected(:network_error)

new()

@spec new() :: t()

Create new client state.

Initializes state with :initializing status and current timestamp.

Example

state = State.new()

record_error(state, error)

@spec record_error(t(), error :: term()) :: t()

Record an error.

Increments the error count and stores the last error.

Example

state = State.record_error(state, %RuntimeError{message: "connection timeout"})

record_request(state)

@spec record_request(t()) :: t()

Record a successful request.

Increments the request count and updates the last_used_at timestamp.

Example

state = State.record_request(state)