Delete old probe logs task

This commit is contained in:
ditatompel 2024-05-06 18:40:09 +07:00
parent 34e4d8c98d
commit 9aad56103a
No known key found for this signature in database
GPG key ID: 31D3D06D77950979

View file

@ -104,9 +104,19 @@ func (repo *CronRepo) postRunTask(id int, nextRun int64, runtime float64) {
func (repo *CronRepo) execCron(slug string) { func (repo *CronRepo) execCron(slug string) {
switch slug { switch slug {
case "something": case "delete_old_probe_logs":
fmt.Println("Running task", slug) fmt.Println("Running task", slug)
// do task repo.deleteOldProbeLogs()
break 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)
}
}