We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Starting only what a FLAME runner needs
almirsarajcic
When FLAME boots a remote runner, it starts your application there, so your application has to decide which supervision children belong on that runner. Here is how ElixirDrops.Application tags each child and filters the list at boot:
defmodule Demo do
def children(child_specs, is_parent?, is_flame?) do
Enum.flat_map(child_specs, fn
{:always, spec} -> [spec]
{:parent, spec} -> if is_parent?, do: [spec], else: []
{:flame, spec} -> if is_flame?, do: [spec], else: []
end)
end
end
specs = [always: :pubsub, parent: :endpoint, flame: :screenshot_pool]
# is_parent? = is_nil(FLAME.Parent.get())
# is_flame? = !is_parent? || FLAME.Backend.impl() == FLAME.LocalBackend
IO.inspect(Demo.children(specs, true, false), label: "parent, FLAME.FlyBackend")
IO.inspect(Demo.children(specs, false, true), label: "remote runner, FLAME.FlyBackend")
IO.inspect(Demo.children(specs, true, true), label: "single node, FLAME.LocalBackend")
parent, FLAME.FlyBackend: [:pubsub, :endpoint]
remote runner, FLAME.FlyBackend: [:pubsub, :screenshot_pool]
single node, FLAME.LocalBackend: [:pubsub, :endpoint, :screenshot_pool]
FLAME.Parent.get/0 reads the FLAME_PARENT environment variable that a backend sets on the machine it boots, and returns nil when it is missing. So is_parent? is true on the node you deployed and false on a runner. FLAME.Backend.impl/0 is just Application.get_env(:flame, :backend, FLAME.LocalBackend), the same value on both sides.
Read is_flame? carefully. It is true on every runner, and also true on your own node whenever the configured backend is FLAME.LocalBackend. That second half matters because FLAME.LocalBackend boots no machine at all. It builds a parent struct in memory and runs your function on the node you already have, so FLAME_PARENT is never set and is_parent? stays true. There is no second node for the tags to split.
The practical consequence: with a real backend, :flame children start on the runner and not on your node. Under FLAME.LocalBackend every tag matches at once, so a child you meant for the runner starts next to your Endpoint in dev. The tag names are an ElixirDrops convention, not something FLAME defines or reads.
copied to clipboard