From 308b2590611fef91efb3f5506721d0672606265b Mon Sep 17 00:00:00 2001 From: Jean-Francois Cloutier Date: Mon, 31 Jan 2022 15:26:11 -0500 Subject: [PATCH] Reset state on recovery if no item files Whether or not there are zero valid item files --- lib/jackalope/persistent_work_list.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/jackalope/persistent_work_list.ex b/lib/jackalope/persistent_work_list.ex index 1b97f1e..e6ef0d5 100644 --- a/lib/jackalope/persistent_work_list.ex +++ b/lib/jackalope/persistent_work_list.ex @@ -381,9 +381,12 @@ defmodule Jackalope.PersistentWorkList do delta_time = Expiration.now() - latest_time(state) - expirations = + item_files = File.ls!(state.data_dir) |> Enum.filter(&Regex.match?(~r/.*\.item/, &1)) + + expirations = + item_files |> Enum.reduce( [], fn item_file, acc -> @@ -408,7 +411,7 @@ defmodule Jackalope.PersistentWorkList do item_indices = Map.keys(expirations) - if Enum.empty?(item_indices) do + if Enum.empty?(item_files) do reset_state(state) else bottom_index = Enum.min(item_indices)