Skip to content

Commit

Permalink
make GC run every 23:00 hours instead
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintWish committed Oct 2, 2024
1 parent 0b757c3 commit 67a34a7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/app/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,29 @@ func (a *App) SetupDatabase() error {

// This is for databases that we use a cache to make writing faster.
func (a *App) SetupDatabaseAutoSave() {
cron := cron.New()
cron.AddFunc("*/30 * * * *", func(){ //This runs every 30 minutes.
syncCron := cron.New()
syncCron.AddFunc("*/30 * * * *", func(){ //This runs every 30 minutes.
a.Logger.Info("Syncing data to disk")
t1 := time.Now()
if err := a.DB.SyncToDisk(); err != nil {
a.Logger.Error("Failed to sync data to disk!", "error", err)
return
}
a.Logger.Info("Finished syncing data to disk", "ping", time.Since(t1))
})
syncCron.Start()

gcCron := cron.New()
gcCron.AddFunc("0 23 * * *", func(){ //This runs at 23:00 every day.
a.Logger.Info("Running database garbage collection")
t1 := time.Now()
if err := a.DB.RunGC(); err != nil {
a.Logger.Error("Failed to run garbage collection!", "error", err)
return
}
a.Logger.Info("Finished syncing to disk and running garbage collection", "ping", time.Since(t1))
a.Logger.Info("Finished running garbage collection", "ping", time.Since(t1))
})
cron.Start()
gcCron.Start()
}

// TODO: Move this to database package.
Expand Down

0 comments on commit 67a34a7

Please sign in to comment.