diff --git a/apps/server/lib/lexical/server/task_queue.ex b/apps/server/lib/lexical/server/task_queue.ex index 1ec6070bc..fb58a9686 100644 --- a/apps/server/lib/lexical/server/task_queue.ex +++ b/apps/server/lib/lexical/server/task_queue.ex @@ -71,7 +71,7 @@ defmodule Lexical.Server.TaskQueue do defp maybe_log_task(reason, request_id), do: Logger.warning("Request id #{request_id} failed with reason #{inspect(reason)}") - defp as_task(request_id, {m, f, a}) do + defp as_task(request_id, {m, f, a} = mfa) do handler = fn -> try do case apply(m, f, a) do @@ -93,7 +93,7 @@ defmodule Lexical.Server.TaskQueue do end end - run_task(handler) + run_task(handler, mfa) end defp write_reply(response) do @@ -119,21 +119,18 @@ defmodule Lexical.Server.TaskQueue do end defp write_error(id, message, code \\ :internal_error) do - error = - ResponseError.new( - code: code, - message: message - ) + error = ResponseError.new(code: code, message: message) Transport.write(%{id: id, error: error}) end - defp run_task(fun) when is_function(fun) do - Task.Supervisor.async_nolink(task_supervisor_name(), fun) + defp run_task(fun, mfa) when is_function(fun) do + task = Task.Supervisor.async_nolink(task_supervisor_name(), fun) + %Task{task | mfa: mfa} end defp cancel_task(%Task{} = task) do - Task.Supervisor.terminate_child(task_supervisor_name(), task.pid) + Process.exit(task.pid, :canceled) end end