prop/vendor/oban_web/lib/oban/web/utils.ex
Graham McIntire caad7d90a7 Mount Oban Web dashboard at /admin/oban
Vendor oban_web 2.12.1 and oban_met 1.1.0 (taken from the
towerops-web2 vendor tree), bump oban to ~> 2.21, and mount the Oban
dashboard at /admin/oban behind the existing require_admin on_mount
hook. Adds an admin-only "Oban" nav link and extends the Dockerfile
to copy vendor/ before deps.get so production builds pick up the
path dependencies.
2026-04-09 14:07:33 -05:00

36 lines
872 B
Elixir

defmodule Oban.Web.Utils do
@moduledoc false
import Ecto.Query
alias Oban.Repo
def has_crons?(conf), do: has_table?(conf, "oban_crons")
def has_workflows?(conf), do: has_table?(conf, "oban_workflows")
def has_pro? do
persistent_cache(:pro?, fn -> Code.ensure_loaded?(Oban.Pro) end)
end
def persistent_cache(key, fun) when is_function(fun, 0) do
case :persistent_term.get(key, nil) do
nil -> tap(fun.(), &:persistent_term.put(key, &1))
val -> val
end
end
defp has_table?(conf, table_name) do
%{name: name, prefix: prefix} = conf
persistent_cache({:table?, name, table_name}, fn ->
query =
from("tables")
|> put_query_prefix("information_schema")
|> where(table_schema: ^prefix, table_name: ^table_name)
|> select(true)
Repo.one(conf, query) == true
end)
end
end