mirror of
https://github.com/plausible/analytics.git
synced 2024-12-26 02:55:02 +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)
|
Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_log_import_error(job) do
|
defp maybe_log_import_error(%Oban.Job{
|
||||||
site = Plausible.Repo.get(Plausible.Site, job.args["site_id"])
|
queue: "google_analytics_imports",
|
||||||
|
args: %{"site_id" => site_id}
|
||||||
|
}) do
|
||||||
|
site = Plausible.Repo.get(Plausible.Site, site_id)
|
||||||
|
|
||||||
if site do
|
if site do
|
||||||
Plausible.Site.import_failure(site) |> Plausible.Repo.update!()
|
Plausible.Workers.ImportGoogleAnalytics.import_failed(site)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -30,8 +30,16 @@ defmodule Plausible.Workers.ImportGoogleAnalytics do
|
|||||||
:ok
|
:ok
|
||||||
|
|
||||||
{:error, error} ->
|
{:error, error} ->
|
||||||
Plausible.Site.import_failure(site)
|
import_failed(site)
|
||||||
|> Repo.update!()
|
|
||||||
|
{: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 ->
|
Enum.each(site.memberships, fn membership ->
|
||||||
if membership.role in [:owner, :admin] do
|
if membership.role in [:owner, :admin] do
|
||||||
@ -39,8 +47,5 @@ defmodule Plausible.Workers.ImportGoogleAnalytics do
|
|||||||
|> Plausible.Mailer.send_email_safe()
|
|> Plausible.Mailer.send_email_safe()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
{:error, error}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user