mirror of
https://github.com/plausible/analytics.git
synced 2024-12-25 02:24:55 +03:00
Send import failed email when job errors
This commit is contained in:
parent
1fb39957a6
commit
f42b694f15
@ -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
|
||||
|
@ -30,17 +30,22 @@ defmodule Plausible.Workers.ImportGoogleAnalytics do
|
||||
:ok
|
||||
|
||||
{:error, error} ->
|
||||
Plausible.Site.import_failure(site)
|
||||
|> Repo.update!()
|
||||
|
||||
Enum.each(site.memberships, fn membership ->
|
||||
if membership.role in [:owner, :admin] do
|
||||
PlausibleWeb.Email.import_failure(membership.user, site)
|
||||
|> Plausible.Mailer.send_email_safe()
|
||||
end
|
||||
end)
|
||||
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
|
||||
PlausibleWeb.Email.import_failure(membership.user, site)
|
||||
|> Plausible.Mailer.send_email_safe()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user