From b2ae6dc3ea45b49f8b6b53a734bba7275f97f7f8 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Fri, 23 Jul 2021 09:45:47 -0400 Subject: [PATCH] fix: flush engine state always --- documentation/topics/pagination.md | 1 - lib/ash/engine/runner.ex | 18 ++++++++++-------- lib/ash/page/keyset.ex | 2 -- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/documentation/topics/pagination.md b/documentation/topics/pagination.md index c5282d53..77182271 100644 --- a/documentation/topics/pagination.md +++ b/documentation/topics/pagination.md @@ -65,7 +65,6 @@ Combining them will result in an error on the query. - Can't go to a specific page number - Can't use aggregate and calculation sorting - For more information on keyset vs offset based pagination, see: - [Offset vs Seek Pagination](https://taylorbrazelton.com/posts/2019/03/offset-vs-seek-pagination/) diff --git a/lib/ash/engine/runner.ex b/lib/ash/engine/runner.ex index a2af468c..95d1b31f 100644 --- a/lib/ash/engine/runner.ex +++ b/lib/ash/engine/runner.ex @@ -48,11 +48,16 @@ defmodule Ash.Engine.Runner do "Synchronous engine starting - #{Enum.map_join(requests, ", ", & &1.name)}" end) - new_state = run_to_completion(state) + try do + new_state = run_to_completion(state) - new_state.requests - |> Enum.reduce(new_state, &add_data(&2, &1.path, &1.data)) - |> Map.put(:resource_notifications, new_state.resource_notifications) + new_state.requests + |> Enum.reduce(new_state, &add_data(&2, &1.path, &1.data)) + |> Map.put(:resource_notifications, new_state.resource_notifications) + after + Process.demonitor(state.engine_monitor_ref, [:flush]) + flush(state) + end end def run_to_completion(state) do @@ -292,10 +297,7 @@ defmodule Ash.Engine.Runner do end defp add_engine_state(state, engine_state) do - new_state = %{state | errors: engine_state.errors ++ state.errors} - - Process.demonitor(state.engine_monitor_ref, [:flush]) - flush(new_state) + %{state | errors: engine_state.errors ++ state.errors} end defp build_dependencies(request, dependencies) do diff --git a/lib/ash/page/keyset.ex b/lib/ash/page/keyset.ex index de7c7274..143663cd 100644 --- a/lib/ash/page/keyset.ex +++ b/lib/ash/page/keyset.ex @@ -55,8 +55,6 @@ defmodule Ash.Page.Keyset do else sort_fields = sort - # |> Enum.map(fn {key, val} when is_atom(key) -> - # end) |> Keyword.keys() |> Enum.sort()