features.ex 533 B

123456789101112131415161718192021222324
  1. defmodule Toy.Features do
  2. use DynamicSupervisor
  3. require Logger
  4. def start_link(init_arg) do
  5. DynamicSupervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
  6. end
  7. def start_repo() do
  8. case DynamicSupervisor.start_child(__MODULE__, Toy.Repo) do
  9. ok = {:ok, _} ->
  10. ok
  11. e = {:error, reason} ->
  12. Logger.warning("Could not start Toy.Repo because : #{inspect(reason)}")
  13. e
  14. end
  15. end
  16. @impl true
  17. def init(_init_arg) do
  18. DynamicSupervisor.init(strategy: :one_for_one)
  19. end
  20. end