This is a worker that runs every minute and deletes expired activities.
It's based heavily on the scheduled activities worker.
max_retries: 5
config :pleroma_job_queue, :queues,
+ activity_expiration: 10,
federator_incoming: 50,
federator_outgoing: 50,
web_push: 50,
status_id_action: {60_000, 3},
password_reset: {1_800_000, 5}
+config :pleroma, Pleroma.ActivityExpiration, enabled: true
+
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"
* `total_user_limit`: the number of scheduled activities a user is allowed to create in total (Default: `300`)
* `enabled`: whether scheduled activities are sent to the job queue to be executed
+## Pleroma.ActivityExpiration
+
+# `enabled`: whether expired activities will be sent to the job queue to be deleted
+
## Pleroma.Web.Auth.Authenticator
* `Pleroma.Web.Auth.PleromaAuthenticator`: default database authenticator
--- /dev/null
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.ActivityExpirationWorker do
+ alias Pleroma.Activity
+ alias Pleroma.ActivityExpiration
+ alias Pleroma.Config
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+ require Logger
+ use GenServer
+ import Ecto.Query
+
+ @schedule_interval :timer.minutes(1)
+
+ def start_link do
+ GenServer.start_link(__MODULE__, nil)
+ end
+
+ @impl true
+ def init(_) do
+ if Config.get([ActivityExpiration, :enabled]) do
+ schedule_next()
+ {:ok, nil}
+ else
+ :ignore
+ end
+ end
+
+ def perform(:execute, expiration_id) do
+ try do
+ expiration =
+ ActivityExpiration
+ |> where([e], e.id == ^expiration_id)
+ |> Repo.one!()
+
+ activity = Activity.get_by_id_with_object(expiration.activity_id)
+ user = User.get_by_ap_id(activity.object.data["actor"])
+ CommonAPI.delete(activity.id, user)
+ rescue
+ error ->
+ Logger.error("#{__MODULE__} Couldn't delete expired activity: #{inspect(error)}")
+ end
+ end
+
+ @impl true
+ def handle_info(:perform, state) do
+ ActivityExpiration.due_expirations(@schedule_interval)
+ |> Enum.each(fn expiration ->
+ PleromaJobQueue.enqueue(:activity_expiration, __MODULE__, [:execute, expiration.id])
+ end)
+
+ schedule_next()
+ {:noreply, state}
+ end
+
+ defp schedule_next do
+ Process.send_after(self(), :perform, @schedule_interval)
+ end
+end
%{
id: Pleroma.ScheduledActivityWorker,
start: {Pleroma.ScheduledActivityWorker, :start_link, []}
+ },
+ %{
+ id: Pleroma.ActivityExpirationWorker,
+ start: {Pleroma.ActivityExpirationWorker, :start_link, []}
}
] ++
hackney_pool_children() ++
--- /dev/null
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.ActivityExpirationWorkerTest do
+ use Pleroma.DataCase
+ alias Pleroma.Activity
+ import Pleroma.Factory
+
+ test "deletes an activity" do
+ activity = insert(:note_activity)
+ expiration = insert(:expiration_in_the_past, %{activity_id: activity.id})
+ Pleroma.ActivityExpirationWorker.perform(:execute, expiration.id)
+
+ refute Repo.get(Activity, activity.id)
+ end
+end