# `Juggernaut.Pool.Env`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/pool/env.ex#L1)

What a worker's `:peer` is started with, as pure functions (design notes §10.5).

  * `render/3` - the configured `env` templates for one worker: `${NAME}` is the
    controller's value (empty when unset), `{worker}` the worker index, or `bootN` for
    the boot lane's slot N (`boot` for `:boot`). With
    `MIX_TEST_PARTITION=_myapp`, worker 3 gets `_myapp_jg3` and boot slot 2
    `_myapp_jgboot2`, so each `config/test.exs` names its own database;
  * `os_env/3` - the whole OS environment change: `MIX_ENV=test`, `MIX_DEPS_PATH` (the
    sandbox's dependency mirror), Mix's build-location variables unset (the sandbox has
    its own `_build`), then the rendered templates;
  * `args/2` - `erl` arguments: `+S` schedulers and a `-pa` for each code path the
    peer needs before Mix loads the project (Elixir's own applications and
    Juggernaut's ebin; Mix adds the project's paths);
  * `size/2` - the pool size within the connection budget.

# `args`

```elixir
@spec args(pos_integer(), [Path.t()]) :: [charlist()]
```

The `erl` arguments: `+S schedulers` and `-pa` for each of `paths`.

# `code_paths`

```elixir
@spec code_paths() :: [Path.t()]
```

The code paths a peer needs before Mix loads the project.

# `os_env`

```elixir
@spec os_env(Path.t(), [{String.t(), String.t()}], keyword()) :: [
  {charlist(), charlist() | false}
]
```

The OS environment change for a worker's peer, as `:peer` takes it: charlist pairs,
`false` to unset.

# `per_worker`

```elixir
@spec per_worker(Juggernaut.Config.t()) :: pos_integer()
```

Database connections one worker is counted for.

# `render`

```elixir
@spec render(
  [{String.t(), String.t()}],
  pos_integer() | :boot | {:boot, pos_integer()},
  %{
    required(String.t()) =&gt; String.t()
  }
) :: [{String.t(), String.t()}]
```

The configured `templates` rendered for `worker`, with the controller's `env`.

# `size`

```elixir
@spec size(Juggernaut.Config.t(), pos_integer(), non_neg_integer()) ::
  {:ok, pos_integer()} | {:error, Juggernaut.Error.t()}
```

The pool size: `Juggernaut.Config.workers/2`, cut down so that every worker's
connections fit the `connections` budget (`budget` connections in all,
`per_worker` each; `:auto` per worker is twice `worker_schedulers`, the pool a repo
sized from `schedulers_online` opens). A budget below one worker is a config error
(exit 2).

`reserve` peers' connections are kept out of the budget for peers started beside the
pool (the server's pool keeps one for the boot lane), as long as one worker still fits;
with no budget it changes nothing.

---

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