Skip to content

Commit f5efe29

Browse files
committed
Unsure, but add match cleanup
1 parent 53aeb29 commit f5efe29

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

config/config.exs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ config :volley, Oban,
1414
notifier: Oban.Notifiers.Postgres,
1515
queues: [default: 10, cleanup: 10],
1616
repo: Volley.Repo,
17-
plugins: [{Oban.Plugins.Cron, []}]
17+
plugins: [
18+
{Oban.Plugins.Cron,
19+
crontab: [
20+
{"* * * * *", Volley.Workers.CleanupWorker, args: %{before: [1, "day"]}}
21+
]}
22+
]
1823

1924
config :volley, :scopes,
2025
user: [

lib/volley/application.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Volley.Application do
1111
VolleyWeb.Telemetry,
1212
Volley.Repo,
1313
{DNSCluster, query: Application.get_env(:volley, :dns_cluster_query) || :ignore},
14-
# TODO: re-add oban{Oban, }
14+
{Oban, Application.fetch_env!(:volley, Oban)},
1515
{Phoenix.PubSub, name: Volley.PubSub},
1616
# Start a worker by calling: Volley.Worker.start_link(arg)
1717
# {Volley.Worker, arg},
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
defmodule Volley.Workers.CleanupWorker do
2+
use Oban.Worker, queue: :cleanup
3+
4+
import Ecto.Query, only: [from: 2]
5+
6+
@impl true
7+
def perform(%Oban.Job{} = job) do
8+
%{
9+
before: [n, interval]
10+
} = job.args
11+
12+
query =
13+
from m in Volley.Scoring.Match,
14+
where: m.updated_at > ago(^n, ^interval) and is_nil(m.owner_id)
15+
16+
Volley.Repo.delete_all(query)
17+
18+
:ok
19+
end
20+
end

0 commit comments

Comments
 (0)