diff --git a/lib/hexdocs/cdn/fastly.ex b/lib/hexdocs/cdn/fastly.ex index 0a4f72d..08e637f 100644 --- a/lib/hexdocs/cdn/fastly.ex +++ b/lib/hexdocs/cdn/fastly.ex @@ -9,18 +9,29 @@ defmodule Hexdocs.CDN.Fastly do service_id = Application.get_env(:hexdocs, service) sleep_time = div(Application.get_env(:hexdocs, :fastly_purge_wait, @fastly_purge_wait), 2) - {:ok, 200, _, _} = post("service/#{service_id}/purge", body) + purge!(service, service_id, body) Task.Supervisor.start_child(Hexdocs.Tasks, fn -> Process.sleep(sleep_time) - {:ok, 200, _, _} = post("service/#{service_id}/purge", body) + purge!(service, service_id, body) Process.sleep(sleep_time) - {:ok, 200, _, _} = post("service/#{service_id}/purge", body) + purge!(service, service_id, body) end) :ok end + defp purge!(service, service_id, body) do + case post("service/#{service_id}/purge", body) do + {:ok, 200, _headers, _body} -> + :ok + + {:ok, status, _headers, body} -> + raise "failed to purge #{service} (service id: #{service_id}), " <> + "status: #{status}, body: #{inspect(body)}" + end + end + defp auth() do Application.get_env(:hexdocs, :fastly_key) end diff --git a/lib/hexdocs/queue.ex b/lib/hexdocs/queue.ex index 196c1cc..fafa24e 100644 --- a/lib/hexdocs/queue.ex +++ b/lib/hexdocs/queue.ex @@ -400,10 +400,17 @@ defmodule Hexdocs.Queue do task = Task.Supervisor.async(Hexdocs.Tasks, fun) case Task.yield(task, :timer.seconds(270)) || Task.shutdown(task) do - {:ok, result} -> result - {:exit, {exception, stacktrace}} -> reraise(exception, stacktrace) - {:exit, reason} -> exit(reason) - nil -> raise "task timeout" + {:ok, result} -> + result + + {:exit, {exception, stacktrace}} when is_exception(exception) -> + reraise(exception, stacktrace) + + {:exit, reason} -> + exit(reason) + + nil -> + raise "task timeout" end end