chore: skip messages that fail to import

This commit is contained in:
Zach Daniel 2023-06-07 23:19:16 -04:00
parent 4b8206154a
commit 4689afa66b

View file

@ -4,6 +4,7 @@ defmodule AshHq.Discord.Poller do
""" """
use GenServer use GenServer
require Logger
@poll_interval :timer.hours(1) @poll_interval :timer.hours(1)
@server_id 711_271_361_523_351_632 @server_id 711_271_361_523_351_632
@ -104,6 +105,7 @@ defmodule AshHq.Discord.Poller do
false false
end) end)
|> Enum.each(fn %{thread: thread, messages: messages} -> |> Enum.each(fn %{thread: thread, messages: messages} ->
try do
author = author =
messages messages
|> Enum.min_by(& &1.timestamp, DateTime) |> Enum.min_by(& &1.timestamp, DateTime)
@ -117,6 +119,9 @@ defmodule AshHq.Discord.Poller do
|> Map.put(:create_timestamp, thread.thread_metadata.create_timestamp) |> Map.put(:create_timestamp, thread.thread_metadata.create_timestamp)
|> Map.put(:messages, Enum.map(messages, &Map.from_struct/1)) |> Map.put(:messages, Enum.map(messages, &Map.from_struct/1))
|> AshHq.Discord.Thread.upsert!() |> AshHq.Discord.Thread.upsert!()
rescue
e ->
Logger.error("Failed to import message:\n #{Exception.format(:error, e, __STACKTRACE__)}")
end) end)
end end