# `LLMProxy.Drain`
[🔗](https://github.com/elixir-vibe/llm_proxy/blob/v0.3.1/lib/llm_proxy/drain.ex#L1)

Runtime drain control for deployment-safe LLMProxy shutdowns.

Drain mode is an operational state: new user work is rejected while existing
work is allowed to finish. Control is exposed through local RPC/release tasks,
not through public HTTP routes. Each active-work lease monitors its owner and
is released if that process exits before it can call `leave/1`.

# `ref`

```elixir
@type ref() :: reference()
```

# `status`

```elixir
@type status() :: %{
  draining: boolean(),
  ready: boolean(),
  serving: boolean(),
  active: %{
    total: non_neg_integer(),
    requests: non_neg_integer(),
    streams: non_neg_integer(),
    agents: non_neg_integer()
  }
}
```

# `work_kind`

```elixir
@type work_kind() :: :request | :stream | :agent
```

# `await_empty`

```elixir
@spec await_empty(timeout()) :: :ok | {:error, :timeout}
```

# `cancel`

```elixir
@spec cancel() :: status()
```

# `child_spec`

```elixir
@spec child_spec(keyword()) :: Supervisor.child_spec()
```

# `draining?`

```elixir
@spec draining?() :: boolean()
```

# `enter`

```elixir
@spec enter(work_kind(), map()) :: {:ok, ref()} | {:error, :draining}
```

# `leave`

```elixir
@spec leave(ref()) :: :ok
```

# `start`

```elixir
@spec start(keyword()) :: status()
```

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

# `status`

```elixir
@spec status() :: status()
```

# `track`

```elixir
@spec track(work_kind(), map(), (-&gt; result)) :: result | {:error, :draining}
when result: term()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
