Add Oban for background jobs.

dev
KKlochko 2 months ago
parent df4518b757
commit 14b0b78e15

@ -1,5 +1,7 @@
[
import_deps: [
:oban,
:ash_oban,
:ash_json_api,
:ash_authentication_phoenix,
:ash_authentication,

@ -7,6 +7,9 @@
# General application configuration
import Config
config :ash_oban, pro?: false
config :decentralised_book_index, Oban, plugins: [{Oban.Plugins.Cron, []}]
config :mime,
extensions: %{"json" => "application/vnd.api+json"},
types: %{"application/vnd.api+json" => ["json"]}

@ -1,4 +1,5 @@
import Config
config :decentralised_book_index, Oban, testing: :manual
config :decentralised_book_index, token_signing_secret: "k+YMBGan4wi4I3DRYRVLNVCOIDIqm+O5"
config :ash, disable_async?: true

@ -10,6 +10,11 @@ defmodule DecentralisedBookIndex.Application do
children = [
DecentralisedBookIndexWeb.Telemetry,
DecentralisedBookIndex.Repo,
{Oban,
AshOban.config(
Application.fetch_env!(:decentralised_book_index, :ash_domains),
Application.fetch_env!(:decentralised_book_index, Oban)
)},
{DNSCluster,
query: Application.get_env(:decentralised_book_index, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: DecentralisedBookIndex.PubSub},

@ -1,6 +1,8 @@
defmodule DecentralisedBookIndexWeb.Router do
use DecentralisedBookIndexWeb, :router
import Oban.Web.Router
import Oban.Web.Router
use AshAuthentication.Phoenix.Router
import AshAuthentication.Plug.Helpers
@ -35,7 +37,8 @@ defmodule DecentralisedBookIndexWeb.Router do
scope "/", DecentralisedBookIndexWeb do
pipe_through :browser
ash_authentication_live_session :moderator_authenticated_routes, on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :moderator_required} do
ash_authentication_live_session :moderator_authenticated_routes,
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :moderator_required} do
live "/books/new", BookLive.Edit, :new
live "/books/:alternative_book_id/new", BookLive.Edit, :new
live "/books/:id/edit", BookLive.Edit, :edit
@ -51,7 +54,8 @@ defmodule DecentralisedBookIndexWeb.Router do
live "/publishers/:id", PublisherLive.Show, :show
end
ash_authentication_live_session :admin_authenticated_routes, on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :admin_required} do
ash_authentication_live_session :admin_authenticated_routes,
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :admin_required} do
live "/servers", DbiServerLive.Index, :index
live "/servers/new", DbiServerLive.Edit, :new
live "/servers/:id/edit", DbiServerLive.Edit, :edit
@ -63,7 +67,8 @@ defmodule DecentralisedBookIndexWeb.Router do
live "/users/:id/edit", UserLive.Edit, :edit
end
ash_authentication_live_session :maybe_authenticated_routes, on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :live_user_optional} do
ash_authentication_live_session :maybe_authenticated_routes,
on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :live_user_optional} do
# in each liveview, add one of the following at the top of the module:
#
# If an authenticated user must be present:
@ -130,5 +135,11 @@ defmodule DecentralisedBookIndexWeb.Router do
live_dashboard "/dashboard", metrics: DecentralisedBookIndexWeb.Telemetry
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
scope "/" do
pipe_through :browser
oban_dashboard("/oban")
end
end
end

@ -33,6 +33,9 @@ defmodule DecentralisedBookIndex.MixProject do
# Type `mix help deps` for examples and options.
defp deps do
[
{:oban, "~> 2.0"},
{:oban_web, "~> 2.0"},
{:ash_oban, "~> 0.4"},
{:bcrypt_elixir, "~> 3.0"},
{:picosat_elixir, "~> 0.2"},
{:sourceror, "~> 1.7", only: [:dev, :test]},
@ -87,12 +90,12 @@ defmodule DecentralisedBookIndex.MixProject do
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ash.setup --quiet", "test"],
"assets.setup": [
"tailwind.install --if-missing",
"esbuild.install --if-missing"
"tailwind.install --if-missing",
"esbuild.install --if-missing"
],
"assets.build": ["tailwind decentralised_book_index", "esbuild decentralised_book_index"],
"assets.deploy": [
"cmd --cd assets npm install",
"cmd --cd assets npm install",
"tailwind decentralised_book_index --minify",
"esbuild decentralised_book_index --minify",
"phx.digest"

@ -3,6 +3,7 @@
"ash_authentication": {:hex, :ash_authentication, "4.5.2", "48621e58b8159fb2a0469b4bbd981aa9de208142313b151a730574578abcc7ac", [:mix], [{:ash, ">= 3.4.29 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ash_postgres, "~> 2.0", [hex: :ash_postgres, repo: "hexpm", optional: true]}, {:assent, "~> 0.2.13", [hex: :assent, repo: "hexpm", optional: false]}, {:bcrypt_elixir, "~> 3.0", [hex: :bcrypt_elixir, repo: "hexpm", optional: false]}, {:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:finch, "~> 0.19", [hex: :finch, repo: "hexpm", optional: false]}, {:igniter, "~> 0.4", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.5", [hex: :joken, repo: "hexpm", optional: false]}, {:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: false]}, {:spark, "~> 2.0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}], "hexpm", "b8d97286b4e2c43bddb2d423e2e858a1baf0180c3f69f63e401e9e9abbfb7105"},
"ash_authentication_phoenix": {:hex, :ash_authentication_phoenix, "2.4.8", "a4dc31e07751d925b3b86c4ea768b59fc88c767722b80143e12c64b7e77b1ccb", [:mix], [{:ash, "~> 3.0", [hex: :ash, repo: "hexpm", optional: false]}, {:ash_authentication, "~> 4.1", [hex: :ash_authentication, repo: "hexpm", optional: false]}, {:ash_phoenix, "~> 2.0", [hex: :ash_phoenix, repo: "hexpm", optional: false]}, {:bcrypt_elixir, "~> 3.0", [hex: :bcrypt_elixir, repo: "hexpm", optional: false]}, {:gettext, "~> 0.26", [hex: :gettext, repo: "hexpm", optional: true]}, {:igniter, ">= 0.5.25 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_html_helpers, "~> 1.0", [hex: :phoenix_html_helpers, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:slugify, "~> 1.3", [hex: :slugify, repo: "hexpm", optional: false]}], "hexpm", "97b449b14ed63da77659b95e4b0e54e4c039ecf690cc65b61074ea3d37513ba6"},
"ash_json_api": {:hex, :ash_json_api, "1.4.19", "94b2d13a48190622380e4df84e306477f357143d78e1afb119eff6130bd5067b", [:mix], [{:ash, "~> 3.3", [hex: :ash, repo: "hexpm", optional: false]}, {:igniter, ">= 0.3.58 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:json_xema, "~> 0.4", [hex: :json_xema, repo: "hexpm", optional: false]}, {:open_api_spex, "~> 3.16", [hex: :open_api_spex, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: false]}, {:plug, "~> 1.11", [hex: :plug, repo: "hexpm", optional: false]}, {:spark, ">= 2.2.10 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}], "hexpm", "04ce13e6a08df2b741a85e6a6cfb496e6c369c2866eac76e9614c18cddb19310"},
"ash_oban": {:hex, :ash_oban, "0.4.5", "f521c03a6276bbba1d42c950d37778165b82e33cd4874dac08a0aaf6df1c1618", [:mix], [{:ash, "~> 3.0", [hex: :ash, repo: "hexpm", optional: false]}, {:oban, "~> 2.15", [hex: :oban, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.18", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "5117f0be61d693c730964382f6170f1d7643759fd3e7c874e25a377b45a23726"},
"ash_phoenix": {:hex, :ash_phoenix, "2.1.19", "4653e105477b7882a82ffe75a16e787c775dbb432b518e3fa11f550ff5afee92", [:mix], [{:ash, ">= 3.4.31 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:igniter, ">= 0.4.3 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.5.6 or ~> 1.6", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.20.3 or ~> 1.0-rc.1", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:spark, ">= 2.2.29 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}], "hexpm", "edf9c976bd8a11219247028fa6b9677abbb96b3a251f3c9b13c823de54b821be"},
"ash_postgres": {:hex, :ash_postgres, "2.5.7", "7f96473d9f59fa4c35975d6bbba6075f2037959b5a1f7c2743e3eeaf3272566c", [:mix], [{:ash, ">= 3.4.65 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ash_sql, ">= 0.2.57 and < 1.0.0-0", [hex: :ash_sql, repo: "hexpm", optional: false]}, {:ecto, ">= 3.12.1 and < 4.0.0-0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.12", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:igniter, ">= 0.5.16 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "df4f05aced37972c7b0c2f9462c0d8ab33f1de7d8217beeb6b2ea8f41175dd41"},
"ash_sql": {:hex, :ash_sql, "0.2.60", "3920e05ba34df913f4e32c7395480687a0372db7c2725b7c7c390b432e28be08", [:mix], [{:ash, ">= 3.4.65 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "dcc3eb8277ccb456cd9ff1e4d9b06699ce9f0502c1dfefee388eb1850817e77e"},
@ -41,6 +42,9 @@
"mix_test_watch": {:hex, :mix_test_watch, "1.2.0", "1f9acd9e1104f62f280e30fc2243ae5e6d8ddc2f7f4dc9bceb454b9a41c82b42", [:mix], [{:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "278dc955c20b3fb9a3168b5c2493c2e5cffad133548d307e0a50c7f2cfbf34f6"},
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
"nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"},
"oban": {:hex, :oban, "2.19.4", "045adb10db1161dceb75c254782f97cdc6596e7044af456a59decb6d06da73c1", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:ecto_sqlite3, "~> 0.9", [hex: :ecto_sqlite3, repo: "hexpm", optional: true]}, {:igniter, "~> 0.5", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5fcc6219e6464525b808d97add17896e724131f498444a292071bf8991c99f97"},
"oban_met": {:hex, :oban_met, "1.0.2", "6a94e0711f70ad4dded62309e103cd85f3500bf6de7bfd5234fc20fb7121b870", [:mix], [{:oban, "~> 2.19", [hex: :oban, repo: "hexpm", optional: false]}], "hexpm", "e9103a9f3ad5a1751143b490b1ee572855a93956ad958b119ccee62c70984473"},
"oban_web": {:hex, :oban_web, "2.11.3", "dc4991263fae8ce21391ebcaebfc0a144ef434bf65f0a9fdafc2dd00424069b8", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:oban, "~> 2.19", [hex: :oban, repo: "hexpm", optional: false]}, {:oban_met, "~> 1.0", [hex: :oban_met, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.7", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}], "hexpm", "ec414e84cc283c3a06309a1167428a7ece0a5cc179c92b835b77c878278adf9b"},
"open_api_spex": {:hex, :open_api_spex, "3.21.2", "6a704f3777761feeb5657340250d6d7332c545755116ca98f33d4b875777e1e5", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.0 or ~> 4.0 or ~> 5.0 or ~> 6.0", [hex: :poison, repo: "hexpm", optional: true]}, {:ymlr, "~> 2.0 or ~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :ymlr, repo: "hexpm", optional: true]}], "hexpm", "f42ae6ed668b895ebba3e02773cfb4b41050df26f803f2ef634c72a7687dc387"},
"owl": {:hex, :owl, "0.12.2", "65906b525e5c3ef51bab6cba7687152be017aebe1da077bb719a5ee9f7e60762", [:mix], [{:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: true]}], "hexpm", "6398efa9e1fea70a04d24231e10dcd66c1ac1aa2da418d20ef5357ec61de2880"},
"phoenix": {:hex, :phoenix, "1.7.20", "6bababaf27d59f5628f9b608de902a021be2cecefb8231e1dbdc0a2e2e480e9b", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "6be2ab98302e8784a31829e0d50d8bdfa81a23cd912c395bafd8b8bfb5a086c2"},

@ -0,0 +1,9 @@
defmodule DecentralisedBookIndex.Repo.Migrations.AddOban do
use Ecto.Migration
use Ecto.Migration
def up, do: Oban.Migration.up()
def down, do: Oban.Migration.down(version: 1)
end
Loading…
Cancel
Save