I have a simple GenServer based app that parses a webpage and plays with the data that it got from it. The code looks roughly like this:
def start_link do
GenServer.start_link(__MODULE__, %{})
end
def init(state) do
schedule_work(1)
{:ok, state}
end
def handle_info(:work, state) do
// Request webpage using HTTPoisson
// Parse data using Floki
// Use it
schedule_work(10 * 60) # Reschedule after 10 minutes
{:noreply, state}
end
defp schedule_work(timeout) do
Process.send_after(self(), :work, timeout * 1000)
end
Today the 3rd party site stopped delivering the correct markup for some time and the parsing failed and crashed the GenServer. Supervisor restarted it and it crashed immediatley. After :max_restarts
the Supervisor eventually stopped the application.
I don't want simply increase the :max_restarts
. Is there a way to tell Supervisor to attempt restarts after certain amount of time? Or should I do more error handling in my parsing code to prevent the process from crashing in the first place (I assume this would be against the "Let it crash" philosophy)?