Compare commits

..

No commits in common. "87ea1f56248fd4f663747f9ec02678dcb983e781" and "85a83d30dfff1d0075f70bb693f185c030cd0990" have entirely different histories.

2 changed files with 16 additions and 41 deletions

View File

@ -8,7 +8,6 @@ defmodule Frenzy.Network do
plug Tesla.Middleware.Logger, log_level: &log_level/1 plug Tesla.Middleware.Logger, log_level: &log_level/1
plug Tesla.Middleware.FollowRedirects plug Tesla.Middleware.FollowRedirects
plug Tesla.Middleware.Compression
# can't use JSON middleware currently, because feed_parser expects to parse the raw body data itself # can't use JSON middleware currently, because feed_parser expects to parse the raw body data itself
# plug Tesla.Middleware.JSON # plug Tesla.Middleware.JSON

View File

@ -24,11 +24,6 @@ defmodule Frenzy.UpdateFeeds do
{:noreply, state} {:noreply, state}
end end
def handle_cast({:update_feed, feed_id, retry_count}, state) do
update_feed(Repo.get(Feed, feed_id), retry_count)
{:noreply, state}
end
def handle_info(:update_feeds, state) do def handle_info(:update_feeds, state) do
update_feeds() update_feeds()
schedule_update() schedule_update()
@ -108,22 +103,22 @@ defmodule Frenzy.UpdateFeeds do
Logger.info("Converted #{count} read items to tombstones") Logger.info("Converted #{count} read items to tombstones")
end end
defp update_feed(feed, retry_count \\ 0) do defp update_feed(feed) do
Logger.debug("Updating #{feed.feed_url}") Logger.debug("Updating #{feed.feed_url}")
case URI.parse(feed.feed_url) do case URI.parse(feed.feed_url) do
%URI{scheme: "gemini"} = uri -> %URI{scheme: "gemini"} = uri ->
update_feed_gemini(feed, uri, retry_count) update_feed_gemini(feed, uri)
%URI{scheme: scheme} when scheme in ["http", "https"] -> %URI{scheme: scheme} when scheme in ["http", "https"] ->
update_feed_http(feed, retry_count) update_feed_http(feed)
%URI{scheme: scheme} -> %URI{scheme: scheme} ->
Logger.warn("Unhandled scheme for feed: #{scheme}") Logger.warn("Unhandled scheme for feed: #{scheme}")
end end
end end
defp update_feed_http(feed, retry_count) do defp update_feed_http(feed) do
case Network.http_get(feed.feed_url) do case Network.http_get(feed.feed_url) do
{:ok, {:ok,
%Tesla.Env{ %Tesla.Env{
@ -153,45 +148,29 @@ defmodule Frenzy.UpdateFeeds do
end end
{:error, reason} -> {:error, reason} ->
if retry_count < 5 do Logger.error("Couldn't load feed #{feed.feed_url}: #{inspect(reason)}")
Process.send_after(
self(),
{:update_feed, feed, retry_count + 1},
trunc(:math.pow(4, retry_count)) * 1000
)
else
Logger.error("Couldn't load feed #{feed.feed_url}: #{inspect(reason)}")
if Frenzy.sentry_enabled?() do if Frenzy.sentry_enabled?() do
Sentry.capture_message("Error loading HTTP feed: #{inspect(reason)}", Sentry.capture_message("Error loading HTTP feed: #{inspect(reason)}",
extra: %{feed_id: feed.id, feed_url: feed.feed_url} extra: %{feed_id: feed.id, feed_url: feed.feed_url}
) )
end
end end
end end
end end
defp update_feed_gemini(feed, feed_uri, retry_count) do defp update_feed_gemini(feed, feed_uri) do
case Network.gemini_request(feed_uri) do case Network.gemini_request(feed_uri) do
{:ok, %Gemini.Response{meta: content_type, body: body}} -> {:ok, %Gemini.Response{meta: content_type, body: body}} ->
do_update_feed(feed, content_type, body) do_update_feed(feed, content_type, body)
{:error, reason} -> {:error, reason} ->
if retry_count < 5 do Logger.error("Couldn't load feed #{feed.feed_url}: #{inspect(reason)}")
Process.send_after(
self(),
{:update_feed, feed, retry_count + 1},
trunc(:math.pow(4, retry_count)) * 1000
)
else
Logger.error("Couldn't load feed #{feed.feed_url}: #{inspect(reason)}")
if Frenzy.sentry_enabled?() do if Frenzy.sentry_enabled?() do
Sentry.capture_message( Sentry.capture_message(
"Error loading Gemini feed: #{inspect(reason)}", "Error loading Gemini feed: #{inspect(reason)}",
extra: %{feed_id: feed.id, feed_url: feed.feed_url} extra: %{feed_id: feed.id, feed_url: feed.feed_url}
) )
end
end end
end end
end end
@ -201,9 +180,6 @@ defmodule Frenzy.UpdateFeeds do
{:ok, rss} -> {:ok, rss} ->
update_feed_from_rss(feed, rss) update_feed_from_rss(feed, rss)
{:error, :no_data} ->
:ok
{:error, reason} -> {:error, reason} ->
Logger.error("Unable to parse feed at '#{feed.feed_url}': #{inspect(reason)}") Logger.error("Unable to parse feed at '#{feed.feed_url}': #{inspect(reason)}")