# `Alternera.PluginHosts.Refresher`
[🔗](https://github.com/10e-ab/alternera-camel/blob/v0.9.0/alternera_plugin_hosts/lib/alternera/plugin_hosts/refresher.ex#L1)

Brings one kind's hosts up to date with the tenant variables they read
(a host entry's `variables`, `PluginHosts.variables/1`). A member reads
them once, as it starts (`PluginHosts.Host`), so a saved variable
reaches it only through a restart.

`variables_changed/2` names a tenant whose variables changed. For each
of the tenant's pools on this node that reads variables, a process of
its own reads the values now and compares them with what each ready
member started with (`Host.fingerprint/1`); when one differs, it
restarts the members one at a time (`Pool.rolling_restart/2`), so no
call fails. A member that is still starting is not compared: it reads
the values again itself once ready (`PluginHosts.Host`). A member
waiting out its backoff after a start that failed on them (a variable
not defined) starts at once (`Host.retry_now/1`). A change while a pool's refresh runs is not lost: the
refresh runs again when it ends, and finds the members up to date or
restarts them again.

A read of the tenant's variables that fails changes nothing: the
members keep the values they started with, and a warning says so.

When the values no longer resolve (a variable the entry lists was
deleted, or a secret no longer decrypts), every ready member is
restarted at once, each draining its calls in flight first
(`Host.restart/1`), and none starts again until the variable is defined:
a host runs with the values its tenant defines, or not at all. A
warning says so. A rolling restart would wait for a member that cannot
start.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `name`

```elixir
@spec name(module()) :: atom()
```

The refresher of `kind`'s hosts.

# `refresh`

```elixir
@spec refresh(module(), {String.t(), String.t()}) :: :ok | {:error, term()}
```

Refreshes the pool of `key` (`PluginHosts.key/2`) now, in the calling
process: `:ok` (up to date, or restarted), `{:error, reasons}` when the
values do not resolve (the members restarted, not to start again until
they do), `{:error, :not_found}` with no such pool here, or the error of
a restart that stopped.

# `secrets_table`

```elixir
@spec secrets_table(module()) :: atom()
```

The ETS table of `kind`'s hosts' secrets that `PluginHosts.host_secrets/3`
keeps, by host key: this process owns it and clears a tenant's rows when
its variables change.

# `start_link`

# `variables_changed`

```elixir
@spec variables_changed(module(), String.t()) :: :ok
```

The tenant's variables changed: refresh its pools on this node that
read variables. Returns at once; a kind whose hosts do not run here
(its supervisor not started) is passed over.

---

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