From d6f11c1840b41fc7b2a5ab3f07824126b7c01c50 Mon Sep 17 00:00:00 2001 From: Ayrat Hudaygulov Date: Fri, 5 Jul 2024 15:48:21 +0100 Subject: [PATCH] more logical cleanup (#23) --- src/VahterBanBot/Cleanup.fs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/VahterBanBot/Cleanup.fs b/src/VahterBanBot/Cleanup.fs index fef3bd3..6cf92be 100644 --- a/src/VahterBanBot/Cleanup.fs +++ b/src/VahterBanBot/Cleanup.fs @@ -19,11 +19,12 @@ type CleanupService( let mutable timer: Timer = null let cleanup _ = task { - let! cleanupMsgs = DB.cleanupOldMessages botConf.CleanupOldLimit - let! vahterStats = DB.getVahterStats (Some botConf.CleanupInterval) - let sb = StringBuilder() - %sb.AppendLine $"Cleaned up {cleanupMsgs} messages from DB which are older than {timeSpanAsHumanReadable botConf.CleanupOldLimit}" + if botConf.CleanupOldMessages then + let! cleanupMsgs = DB.cleanupOldMessages botConf.CleanupOldLimit + %sb.AppendLine $"Cleaned up {cleanupMsgs} messages from DB which are older than {timeSpanAsHumanReadable botConf.CleanupOldLimit}" + + let! vahterStats = DB.getVahterStats (Some botConf.CleanupInterval) %sb.AppendLine(string vahterStats) let msg = sb.ToString() @@ -36,7 +37,7 @@ type CleanupService( interface IHostedService with member this.StartAsync _ = - if botConf.CleanupOldMessages then + if not botConf.IgnoreSideEffects then timer <- new Timer(TimerCallback(cleanup >> ignore), null, TimeSpan.Zero, botConf.CleanupInterval) Task.CompletedTask