Application . put_env ( :sample , Sample.Repo , database: "oban_dev" )
Application . put_env ( :phoenix , :json_library , Jason )
Application . put_env ( :sample , Sample.Endpoint ,
http: [ ip: { 127 , 0 , 0 , 1 } , port: 5001 ] ,
server: true ,
live_view: [ signing_salt: "aaaaaaaa" ] ,
secret_key_base: String . duplicate ( "a" , 64 )
)
Mix . install ( [
{ :plug_cowboy , "~> 2.5" } ,
{ :jason , "~> 1.0" } ,
{ :oban , "~> 2.13" } ,
{ :oban_web , "~> 2.9" , repo: :oban } ,
{ :phoenix , "~> 1.6" } ,
{ :phoenix_live_view , "~> 0.17" } ,
{ :postgrex , "~> 0.16" }
] )
Phoenix LiveView with Oban Web
defmodule Sample.Repo do
use Ecto.Repo , adapter: Ecto.Adapters.Postgres , otp_app: :sample
end
defmodule Sample.ErrorView do
use Phoenix.View , root: ""
def render ( _ , _ ) , do: "error"
end
defmodule Router do
use Phoenix.Router
import Phoenix.LiveView.Router
import Oban.Web.Router
pipeline :browser do
plug ( :accepts , [ "html" ] )
plug ( :fetch_session )
plug ( :fetch_live_flash )
plug ( :protect_from_forgery )
plug ( :put_secure_browser_headers )
end
scope "/" do
pipe_through ( :browser )
oban_dashboard ( "/oban" )
end
end
defmodule Sample.Endpoint do
use Phoenix.Endpoint , otp_app: :sample
@ session_options store: :cookie , key: "_sample_key" , signing_salt: "aaaaaaaa"
socket ( "/live" , Phoenix.LiveView.Socket , websocket: [ connect_info: [ session: @ session_options ] ] )
plug ( Plug.Session , @ session_options )
plug ( Router )
end
defmodule Main do
def call do
children = [
Sample.Repo ,
{ Oban , repo: Sample.Repo , plugins: [ Oban.Web.Plugins.Stats ] } ,
Sample.Endpoint
]
{ :ok , _ } = Supervisor . start_link ( children , strategy: :one_for_one )
end
end
Main . call ( )
System . no_halt ( true )