View Source Unleash.Runtime (Unleash v3.0.0)
Main Runtime implementation for the Unleash SDK.
Like all the official SDKs, this one keeps and serves feature from a local cache
(in our case, based on an :ets
table), including evaluating activation strategies locally.
The features are initialised from a bootstrap file and updated periodically
from the Unleash API in the background, independently of how many feature checks are invoked.
This allows applications using this SDK to get the status of a feature instantaneously and locally, without overloading the Unleash Server with API calls; but it also means that the features might be stale, up to the polling interval or even longer in case of errors contacting the Unleash APIs.
This Runtime is an Elixir Application that comes with its own Supervision Tree, which starts two GenServer worker processes:
Unleash.Repo
, responsible for periodically refreshing the features from the Unleash API Server and maintaining the local cache updated.Unleash.Metrics
, responsible for periodically sending metrics to the Unleash API Server.
The latter can be disabled with disable_metrics: true
; while setting disable_client: true
will disable both of them and the SDK will start in "disconnected mode",
where no features are defined and feature flags values are returned only from
local overrides (see Unleash.Propagation
) and fallback values.
Note that:
- Currently, in "disconnected mode", the SDK won't even load features from the local bootstrap file. That might change in the future, which would allow the SDK to work with a static set of local features initialised from a local file.
- In the test environment, the SDK won't automatically start polling from the API, even if the client is enabled.
You'll have to start it explicitly with
Unleash.Repo.start_polling/0
.
Summary
Functions
Checks if the given feature is enabled.
Returns the variant for the given feature flag.
Starts the Unleash SDK Runtime.
Functions
Checks if the given feature is enabled.
Takes a feature name and a keyword list of options,
which are used to customise the behaviour of the feature check.
See Unleash.enabled_opt/0
for the supported options and their defaults.
Returns a boolean indicating whether the feature flag is enabled.
Can return nil
only if :fallback
was set to nil
and the feature was not found locally.
NOTE: Prefer using Unleash.Macros.enabled?/2
whenever possible. See Unleash.Macros
.
Returns the variant for the given feature flag.
Strategy variants are prioritised. If none is available then it will fallback to using feature variants. For more info on strategy variants see https://docs.getunleash.io/reference/strategy-variants. Feature variants are deprecated, but are still supported for backwards compatibility and you can find more info about them here: https://docs.getunleash.io/reference/feature-toggle-variants
It takes a feature name and a keyword list of options, which are used to customise the behaviour
of the feature check. See Unleash.get_variant_opt/0
for the supported options and their
defaults.
Returns a Unleash.Variant.t/0
representing the selected variant.
A special variant %{enabled: false, name: "disabled"}
will be returned in
any of these scenarios:
- the feature flag is disabled
- the feature flag does not define any strategy variants in the active strategy
- the feature flag does not define any feature variants
- the feature flag does not exist and no fallback has been supplied
NOTE: Prefer using Unleash.Macros.get_variant/2
whenever possible. See Unleash.Macros
.
Starts the Unleash SDK Runtime.
See Unleash.Runtime
for details.