fix: timeouts @ the engine, not the parent process

This commit is contained in:
Zach Daniel 2022-04-08 02:04:26 -04:00
parent 24d9948ddb
commit 20a9f76c8d

View file

@ -68,29 +68,6 @@ defmodule Ash.Engine do
authorize? = opts[:authorize?] authorize? = opts[:authorize?]
actor = opts[:actor] actor = opts[:actor]
if opts[:timeout] && is_integer(opts[:timeout]) do
parent = self()
Task.start_link(fn ->
ref = Process.monitor(parent)
timeout = opts[:timeout]
receive do
{:DOWN, ^ref, _, ^parent, _} ->
:ok
after
timeout ->
Logger.error("""
Engine timed out processing requests.
#{Enum.map_join(requests, "\n", &summarize(&1))}
""")
exit(:timeout)
end
end)
end
opts = Keyword.put(opts, :callers, [self() | Process.get(:"$callers", [])]) opts = Keyword.put(opts, :callers, [self() | Process.get(:"$callers", [])])
# If the requests are invalid, this is a framework level error # If the requests are invalid, this is a framework level error
@ -249,6 +226,32 @@ defmodule Ash.Engine do
def init(opts) do def init(opts) do
Process.put(:"$callers", opts[:callers]) Process.put(:"$callers", opts[:callers])
if opts[:timeout] && is_integer(opts[:timeout]) do
parent = self()
Task.start_link(fn ->
ref = Process.monitor(parent)
timeout = opts[:timeout]
receive do
{:DOWN, ^ref, _, ^parent, _} ->
:ok
other ->
IO.inspect(other, label: "GOT THING")
after
timeout ->
Logger.error("""
Engine timed out processing requests.
#{Enum.map_join(opts[:requests], "\n", &summarize(&1))}
""")
exit(:timeout)
end
end)
end
state = state =
%__MODULE__{ %__MODULE__{
requests: opts[:requests], requests: opts[:requests],