Skip to content
Snippets Groups Projects
Commit 2915dc5f authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

Merge branch 'feat/delete-outdated-consents' into 'dev'

feat(consents): delete outdated consents

See merge request !111
parents 66ead2e3 d2de6f94
Branches
No related tags found
3 merge requests!120feat: Allow to download all consents,!117chore: Set GRDF token refresh as an option,!111feat(consents): delete outdated consents
Pipeline #111211 passed
package models
import (
"log"
"time"
)
// deleteOutdatedConsents hard deletes outdated consents where end_date is more than 5 years old
func deleteOutdatedConsents[T GrdfConsent | SgeConsent](dh *DataHandler, model *T, consentType string) {
log.Printf("Running %v outdated consents cleanup", consentType)
cutoffDate := time.Now().AddDate(-5, 0, 0)
result := dh.sqlClient.Unscoped().
Where("end_date < ?", cutoffDate).
Delete(model)
log.Printf("nb of rows %v", result.RowsAffected)
if result.Error != nil {
log.Printf("Error deleting outdated %s consents: %v\n", consentType, result.Error)
return
}
if result.RowsAffected > 0 {
log.Printf("Successfully deleted %d outdated %s consent(s) created before %v\n",
result.RowsAffected,
consentType,
cutoffDate.Format("2006-01-02"))
}
}
func DeleteOutdatedConsents(dh *DataHandler) {
deleteOutdatedConsents(dh, &GrdfConsent{}, "GRDF")
deleteOutdatedConsents(dh, &SgeConsent{}, "SGE")
}
......@@ -59,6 +59,21 @@ func main() {
}
}()
// Deletes outdated consents every 24h
dh := models.NewDataHandler()
dailyTicker := time.NewTicker(time.Hour * 24)
go func() {
for {
select {
case <-dailyTicker.C:
models.DeleteOutdatedConsents(dh)
case <-quit:
dailyTicker.Stop()
return
}
}
}()
// Serve locally with https
log.Fatal(http.ListenAndServeTLS(":"+strconv.Itoa(httpsPort), "./dev_certificates/localhost.crt", "./dev_certificates/localhost.key", rootMux.Router))
// log.Fatal(http.ListenAndServe(":"+strconv.Itoa(httpsPort), rootMux.Router))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment