Hi, I have a simple GenServer
which loads all record of a table of my database and store on itself.
It works good for me, but I have this error when I delete a record on database I send a request to my GenServer to check if my table is empty, it creates a basic info immediately. But it stops my db and Repo module even though I put Repo
in my Application file.
could not lookup Ecto repo MishkaDatabase.Repo because it was not started or it does not exist
Then, if I want to work with this, I should put sending request into a Task with a sleep time to work like this:
Task.Supervisor.async_nolink(MishkaDatabase.Public.ReStartSettingAgentTaskSupervisor, fn ->
:timer.sleep(10000)
MishkaDatabase.Cache.SettingCache.stop()
end)
If I user
MishkaDatabase.Cache.SettingCache.stop()
without Task or sleep time, it stops my Repo module.
My application:
defmodule MishkaDatabase.Application do
@moduledoc false
use Application
@impl true
def start(_type, _args) do
children = [
{MishkaDatabase.Cache.MnesiaToken, []},
{MishkaDatabase.Cache.RandomCode, []},
MishkaDatabase.Repo,
{MishkaDatabase.Cache.SettingCache, []},
{Task.Supervisor, name: MishkaDatabase.Public.ReStartSettingAgentTaskSupervisor}
]
opts = [strategy: :one_for_one, name: MishkaDatabase.Supervisor]
Supervisor.start_link(children, opts)
end
end
After stopping Repo, I should re-start server to work again!!! I am using {:ecto_sql, "~> 3.7"}
and my project is an umbrella project.