Add Cron worker to clean up orphaned apps hourly
This commit is contained in:
parent
7bd0750787
commit
a1951f3af7
4 changed files with 41 additions and 1 deletions
|
|
@ -165,4 +165,10 @@ defmodule Pleroma.Web.OAuth.App do
|
|||
end
|
||||
|
||||
def maybe_update_owner(_), do: :ok
|
||||
|
||||
@spec remove_orphans() :: :ok
|
||||
def remove_orphans() do
|
||||
from(a in __MODULE__, where: is_nil(a.user_id))
|
||||
|> Repo.delete_all()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
21
lib/pleroma/workers/cron/app_cleanup_worker.ex
Normal file
21
lib/pleroma/workers/cron/app_cleanup_worker.ex
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Workers.Cron.AppCleanupWorker do
|
||||
@moduledoc """
|
||||
Cleans up registered apps that were never associated with a user.
|
||||
"""
|
||||
|
||||
use Oban.Worker, queue: "background"
|
||||
|
||||
alias Pleroma.Web.OAuth.App
|
||||
|
||||
@impl true
|
||||
def perform(_job) do
|
||||
App.remove_orphans()
|
||||
end
|
||||
|
||||
@impl true
|
||||
def timeout(_job), do: :timer.seconds(30)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue