# `Juggernaut.Server.Client`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/server/client.ex#L1)

The client side of `mix juggernaut.server` (design notes §12): finds the server of a
checkout from `server/server.json` and `server/token`, sends one request and relays the
frames that come back.

`attach/3` is what `mix juggernaut` and `mix juggernaut.check` do when a server is
reachable: the job's stdout goes through the Mix shell, its stderr to stderr (or
`ctx.progress`), the queue position to stderr, and its exit code is returned. An
address file whose server no longer answers is treated as no server.

# `address`

```elixir
@type address() :: %{port: :inet.port_number(), token: String.t()}
```

Where a server listens.

# `address`

```elixir
@spec address(Path.t()) :: {:ok, address()} | :none
```

The address of `root`'s server, or `:none` when no address file is readable.

# `attach`

```elixir
@spec attach(String.t(), [String.t()], map()) :: {:attached, 0..3} | :none
```

Runs `kind` (`run` or `check`) with `argv` on the server of `ctx.root`: `{:attached,
code}` with the job's exit code, or `:none` when no server answers.

# `print`

```elixir
@spec print(map(), map()) :: :ok
```

Shows one reply frame of a job: its output, its queue position or a refusal.

# `request`

```elixir
@spec request(Path.t(), String.t(), map(), (map() -&gt; term())) ::
  {:ok, map()} | :none | {:error, Juggernaut.Error.t()}
```

Sends `kind` (`run`, `check`, `status`, `stop`) with `fields` to `root`'s server and
calls `on_frame` with each reply frame until the last. Returns `{:ok, last_frame}`,
`:none` when no server answers, or an infrastructure error when the connection drops.

---

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