Latest-version sweep across the Oban stack. Final state: oban 2.22.1 (hexpm) oban_pro 1.7.0 (vendored, latest in licensed repo) oban_met 1.1.0 (vendored, latest in licensed repo and hexpm) oban_web 2.12.3 (vendored from public hexpm) oban_web was re-vendored via `mix hex.package fetch oban_web 2.12.3 --unpack` and dropped into vendor/oban_web. No local mods to preserve — vendor commit history shows the dir was a vanilla import.
39 lines
1 KiB
Elixir
39 lines
1 KiB
Elixir
defmodule Oban.Web.Utils do
|
|
@moduledoc false
|
|
|
|
import Ecto.Query
|
|
|
|
alias Oban.Repo
|
|
|
|
def has_crons?(conf), do: has_table?("oban_crons", conf)
|
|
|
|
def has_workflows?(conf), do: has_table?("oban_workflows", conf)
|
|
|
|
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?(_table_name, %{engine: Oban.Engines.Dolphin}), do: false
|
|
defp has_table?(_table_name, %{engine: Oban.Engines.Lite}), do: false
|
|
|
|
defp has_table?(table_name, conf) do
|
|
%{name: oban_name, prefix: prefix} = conf
|
|
|
|
persistent_cache({:table?, oban_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
|