2021-04-26 11:32:18 +03:00
|
|
|
defmodule ErrorReporter do
|
|
|
|
def handle_event([:oban, :job, :exception], measure, %{job: job} = meta, _) do
|
|
|
|
extra =
|
|
|
|
job
|
|
|
|
|> Map.take([:id, :args, :meta, :queue, :worker])
|
|
|
|
|> Map.merge(measure)
|
|
|
|
|
2022-04-08 11:05:21 +03:00
|
|
|
on_job_exception(job)
|
2022-03-21 15:24:45 +03:00
|
|
|
|
2022-04-27 21:37:02 +03:00
|
|
|
Sentry.capture_exception(meta.reason, stacktrace: meta.stacktrace, extra: extra)
|
2021-04-26 11:32:18 +03:00
|
|
|
end
|
|
|
|
|
2022-04-27 21:37:02 +03:00
|
|
|
def handle_event([:oban, :notifier, :exception], _timing, meta, _) do
|
|
|
|
extra = Map.take(meta, ~w(channel payload)a)
|
|
|
|
|
|
|
|
Sentry.capture_exception(meta.reason, stacktrace: meta.stacktrace, extra: extra)
|
|
|
|
end
|
|
|
|
|
|
|
|
def handle_event([:oban, :plugin, :exception], _timing, meta, _) do
|
|
|
|
extra = Map.take(meta, ~w(plugin)a)
|
|
|
|
|
|
|
|
Sentry.capture_exception(meta.reason, stacktrace: meta.stacktrace, extra: extra)
|
2021-04-26 11:32:18 +03:00
|
|
|
end
|
2022-03-21 15:24:45 +03:00
|
|
|
|
2022-04-08 11:05:21 +03:00
|
|
|
defp on_job_exception(%Oban.Job{
|
2022-03-22 12:59:30 +03:00
|
|
|
queue: "google_analytics_imports",
|
2022-04-08 11:05:21 +03:00
|
|
|
args: %{"site_id" => site_id},
|
|
|
|
state: "executing",
|
|
|
|
attempt: attempt,
|
|
|
|
max_attempts: max_attempts
|
|
|
|
})
|
|
|
|
when attempt >= max_attempts do
|
2022-03-22 12:59:30 +03:00
|
|
|
site = Plausible.Repo.get(Plausible.Site, site_id)
|
2022-03-21 15:24:45 +03:00
|
|
|
|
|
|
|
if site do
|
2022-03-22 12:59:30 +03:00
|
|
|
Plausible.Workers.ImportGoogleAnalytics.import_failed(site)
|
2022-03-21 15:24:45 +03:00
|
|
|
end
|
|
|
|
end
|
2022-04-08 11:05:21 +03:00
|
|
|
|
|
|
|
defp on_job_exception(%Oban.Job{
|
|
|
|
queue: "google_analytics_imports",
|
|
|
|
args: %{"site_id" => site_id},
|
|
|
|
state: "executing"
|
|
|
|
}) do
|
|
|
|
Plausible.ClickhouseRepo.clear_imported_stats_for(site_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp on_job_exception(_job), do: :ignore
|
2021-04-26 11:32:18 +03:00
|
|
|
end
|