I have a function that spawns a process, which performs a query like so:
def trigger_schedule(u = %User{}) do
spawn(fn ->
(Repo.preload(p, :tasks)).tasks
|> Enum.map(fn ts -> trigger_schedule(ts) end)
end)
u
end
This code is triggered by certain actions, and is simply meant to run in the background. However, when I run tests, I start seeing this:
00:37:33.324 [error] Postgrex.Protocol (#PID<0.789.0>) disconnected: ** (DBConnection.ConnectionError) owner #PID<0.1531.0> exited while client #PID<0.1533.0> is still running with: shutdown
Is performing queries inside of a spaned function not proper, or is there a way to get around this error? I assume this has something to do with the PG connection pool...