forked from wojtekmach/mix_install_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oban.exs
60 lines (48 loc) · 1.12 KB
/
oban.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Mix.install([
{:ecto_sql, "~> 3.6.2"},
{:postgrex, "~> 0.15.0"},
{:oban, "~> 2.8"}
])
Application.put_env(:myapp, Repo,
database: "mix_install_oban"
# You may need the below depending on your setup. Uncomment as neeeded.
# port: 5454,
# username: "your_username",
# password: "your_password"
)
defmodule Repo do
use Ecto.Repo,
adapter: Ecto.Adapters.Postgres,
otp_app: :myapp
end
defmodule Migration0 do
use Ecto.Migration
def change do
Oban.Migrations.up()
end
end
defmodule Main do
def main do
children = [
Repo,
{Oban, repo: Repo, plugins: [Oban.Plugins.Pruner], queues: [default: 10]}
]
Repo.__adapter__().storage_down(Repo.config())
Repo.__adapter__().storage_up(Repo.config())
{:ok, _} = Supervisor.start_link(children, strategy: :one_for_one)
Ecto.Migrator.run(Repo, [{0, Migration0}], :up, all: true)
Oban.insert!(Worker.new(%{id: 1}))
Oban.insert!(Worker.new(%{id: 2}))
Oban.Job
|> Repo.all()
|> IO.inspect()
end
end
defmodule Worker do
use Oban.Worker
@impl true
def perform(%Oban.Job{}) do
:ok
end
end
Main.main()