Send import failed email when job errors

This commit is contained in:
Uku Taht 2022-03-22 11:59:30 +02:00
parent 1fb39957a6
commit f42b694f15
2 changed files with 20 additions and 12 deletions

View File

@ -14,11 +14,14 @@ defmodule ErrorReporter do
Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: meta)
end
defp maybe_log_import_error(job) do
site = Plausible.Repo.get(Plausible.Site, job.args["site_id"])
defp maybe_log_import_error(%Oban.Job{
queue: "google_analytics_imports",
args: %{"site_id" => site_id}
}) do
site = Plausible.Repo.get(Plausible.Site, site_id)
if site do
Plausible.Site.import_failure(site) |> Plausible.Repo.update!()
Plausible.Workers.ImportGoogleAnalytics.import_failed(site)
end
end
end

View File

@ -30,8 +30,16 @@ defmodule Plausible.Workers.ImportGoogleAnalytics do
:ok
{:error, error} ->
Plausible.Site.import_failure(site)
|> Repo.update!()
import_failed(site)
{:error, error}
end
end
def import_failed(site) do
site = Repo.preload(site, memberships: :user)
Plausible.Site.import_failure(site) |> Repo.update!()
Enum.each(site.memberships, fn membership ->
if membership.role in [:owner, :admin] do
@ -39,8 +47,5 @@ defmodule Plausible.Workers.ImportGoogleAnalytics do
|> Plausible.Mailer.send_email_safe()
end
end)
{:error, error}
end
end
end