File size: 544 Bytes
c27e67a | 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 | defmodule Plausible.Workers.CleanInvitations do
use Plausible.Repo
use Oban.Worker, queue: :clean_invitations
@cutoff Duration.new!(hour: -48)
@impl Oban.Worker
def perform(_job) do
cutoff_time =
NaiveDateTime.utc_now(:second)
|> NaiveDateTime.shift(@cutoff)
Repo.delete_all(
from ti in Plausible.Teams.Invitation,
where: ti.inserted_at < ^cutoff_time
)
Repo.delete_all(
from ti in Plausible.Teams.SiteTransfer,
where: ti.inserted_at < ^cutoff_time
)
:ok
end
end
|