cronjob to clean mod logs

This commit is contained in:
Luna D 2021-11-08 11:41:13 +01:00
parent ee1cca8fe4
commit c776a29094
No known key found for this signature in database
GPG key ID: 81AF416F2CC36FC8
3 changed files with 12 additions and 0 deletions

View file

@ -9,6 +9,7 @@ background() {
mix run -e 'Philomena.Release.update_channels()'
mix run -e 'Philomena.Release.verify_artist_links()'
mix run -e 'Philomena.Release.update_stats()'
mix run -e 'Philomena.Release.clean_moderation_logs()'
sleep 300
done

View file

@ -74,4 +74,10 @@ defmodule Philomena.ModerationLogs do
def delete_moderation_log(%ModerationLog{} = moderation_log) do
Repo.delete(moderation_log)
end
def cleanup! do
ModerationLog
|> where([ml], ml.created_at < ago(2, "week"))
|> Repo.delete_all()
end
end

View file

@ -29,6 +29,11 @@ defmodule Philomena.Release do
PhilomenaWeb.StatsUpdater.update_stats!()
end
def clean_moderation_logs do
start_app()
Philomena.ModerationLogs.cleanup!()
end
defp repos do
Application.fetch_env!(@app, :ecto_repos)
end