feat(retention): run eviction from an Oban cron worker
Adds config :pleroma, :retention (disabled by default) and an hourly crontab entry that evicts one bounded batch per run.
This commit is contained in:
parent
1ebcd4f79d
commit
cd796f007d
4 changed files with 126 additions and 1 deletions
37
lib/pleroma/workers/cron/retention_worker.ex
Normal file
37
lib/pleroma/workers/cron/retention_worker.ex
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# 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.RetentionWorker do
|
||||
@moduledoc """
|
||||
Evicts one batch of old remote threads per run, see `Pleroma.Retention`.
|
||||
"""
|
||||
|
||||
use Oban.Worker, queue: :background, max_attempts: 1
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Retention
|
||||
|
||||
require Logger
|
||||
|
||||
@impl true
|
||||
def perform(_job) do
|
||||
config = Config.get(:retention, [])
|
||||
|
||||
if config[:enabled] do
|
||||
stats = Retention.run(config)
|
||||
|
||||
if stats.contexts > 0 do
|
||||
Logger.info(
|
||||
"Retention: evicted #{stats.contexts} threads " <>
|
||||
"(#{stats.objects} objects, #{stats.activities} activities)"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
@impl true
|
||||
def timeout(_job), do: :timer.minutes(30)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue