From 9aad56103a490897fbfdabf757990e85b788f584 Mon Sep 17 00:00:00 2001 From: ditatompel Date: Mon, 6 May 2024 18:40:09 +0700 Subject: [PATCH] Delete old probe logs task --- internal/repo/cron.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/repo/cron.go b/internal/repo/cron.go index 93a5b81..aec1f57 100644 --- a/internal/repo/cron.go +++ b/internal/repo/cron.go @@ -104,9 +104,19 @@ func (repo *CronRepo) postRunTask(id int, nextRun int64, runtime float64) { func (repo *CronRepo) execCron(slug string) { switch slug { - case "something": + case "delete_old_probe_logs": fmt.Println("Running task", slug) - // do task + repo.deleteOldProbeLogs() break } } + +func (repo *CronRepo) deleteOldProbeLogs() { + // for now, we only delete stats older than 2 days + startTs := time.Now().AddDate(0, 0, -2).Unix() + query := `DELETE FROM tbl_probe_log WHERE date_checked < ?` + _, err := repo.db.Exec(query, startTs) + if err != nil { + fmt.Println(err) + } +}