Add script to remove old reminders

This commit is contained in:
jude 2024-10-12 22:12:01 +01:00
parent 894961e2cd
commit 6340f5a20f
4 changed files with 18 additions and 1 deletions

View File

@ -59,6 +59,7 @@ assets = [
["reminder-dashboard/dist/index.html", "lib/reminder-rs/static/index.html", "644"], ["reminder-dashboard/dist/index.html", "lib/reminder-rs/static/index.html", "644"],
["conf/default.env", "etc/reminder-rs/config.env", "600"], ["conf/default.env", "etc/reminder-rs/config.env", "600"],
["conf/Rocket.toml", "etc/reminder-rs/Rocket.toml", "600"], ["conf/Rocket.toml", "etc/reminder-rs/Rocket.toml", "600"],
["bin/reminder-rs-clean-old", "usr/bin/reminder-rs-clean-old", "755"],
# ["nginx/reminder-rs", "etc/nginx/sites-available/reminder-rs", "755"] # ["nginx/reminder-rs", "etc/nginx/sites-available/reminder-rs", "755"]
] ]
conf-files = [ conf-files = [

12
bin/reminder-rs-clean-old Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Load environment
source /etc/reminder-rs/config.env
if [ -z "${SENT_CLEAN_AGE}" ]; then
mysql -D reminders -e "DELETE FROM reminders WHERE status != 'pending' AND \`utc_time\` < NOW() - INTERVAL ${SENT_CLEAN_AGE} MONTH"
fi;
if [ -z "${TOTAL_CLEAN_AGE}" ]; then
mysql -D reminders -e "DELETE FROM reminders WHERE \`utc_time\` < NOW() - INTERVAL ${TOTAL_CLEAN_AGE} MONTH"
fi;

View File

@ -16,4 +16,7 @@ OAUTH2_CLIENT_ID=
OAUTH2_CLIENT_SECRET= OAUTH2_CLIENT_SECRET=
REPORT_EMAIL= REPORT_EMAIL=
LOG_TO_DATABASE=1 # Delete sent/deleted/failed reminders after this many months
SENT_CLEAN_AGE=
# Delete all reminders after this many months
TOTAL_CLEAN_AGE=

View File

@ -29,6 +29,7 @@ use std::{
}; };
use chrono_tz::Tz; use chrono_tz::Tz;
use clap::Subcommand;
use log::warn; use log::warn;
use poise::serenity_prelude::{ use poise::serenity_prelude::{
model::{ model::{