improve oban logging

This commit is contained in:
2023-02-04 20:48:14 -05:00
parent f6b5fc17fa
commit 064d2d3988
6 changed files with 105 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ defmodule Cannery.Application do
@moduledoc false
use Application
alias Cannery.ErrorReporter
@impl true
def start(_type, _args) do
@@ -17,16 +18,24 @@ defmodule Cannery.Application do
# Start the Endpoint (http/https)
CanneryWeb.Endpoint,
# Add Oban
{Oban, oban_config()}
{Oban, oban_config()},
Cannery.Repo.Migrator
# Start a worker by calling: Cannery.Worker.start_link(arg)
# {Cannery.Worker, arg}
]
# Automatically migrate on start in prod
children =
if Application.get_env(:cannery, Cannery.Application, automigrate: false)[:automigrate],
do: children ++ [Cannery.Repo.Migrator],
else: children
# Oban events logging https://hexdocs.pm/oban/Oban.html#module-reporting-errors
:ok =
:telemetry.attach_many(
"oban-logger",
[
[:oban, :job, :exception],
[:oban, :job, :start],
[:oban, :job, :stop]
],
&ErrorReporter.handle_event/4,
[]
)
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options