Skip to content

Commit

Permalink
more logical cleanup (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Szer authored Jul 5, 2024
1 parent a81a8ea commit d6f11c1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/VahterBanBot/Cleanup.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down

0 comments on commit d6f11c1

Please sign in to comment.