From 6340f5a20fd10db7445f595aed73a9d0f76c624f Mon Sep 17 00:00:00 2001 From: jude Date: Sat, 12 Oct 2024 22:12:01 +0100 Subject: [PATCH] Add script to remove old reminders --- Cargo.toml | 1 + bin/reminder-rs-clean-old | 12 ++++++++++++ conf/default.env | 5 ++++- src/main.rs | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100755 bin/reminder-rs-clean-old diff --git a/Cargo.toml b/Cargo.toml index 49e4fbe..5be0d50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ assets = [ ["reminder-dashboard/dist/index.html", "lib/reminder-rs/static/index.html", "644"], ["conf/default.env", "etc/reminder-rs/config.env", "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"] ] conf-files = [ diff --git a/bin/reminder-rs-clean-old b/bin/reminder-rs-clean-old new file mode 100755 index 0000000..7b0739d --- /dev/null +++ b/bin/reminder-rs-clean-old @@ -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; diff --git a/conf/default.env b/conf/default.env index 853e80b..a5bbd64 100644 --- a/conf/default.env +++ b/conf/default.env @@ -16,4 +16,7 @@ OAUTH2_CLIENT_ID= OAUTH2_CLIENT_SECRET= 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= diff --git a/src/main.rs b/src/main.rs index df2cd93..1513f9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,7 @@ use std::{ }; use chrono_tz::Tz; +use clap::Subcommand; use log::warn; use poise::serenity_prelude::{ model::{