chore(cron): add some logging

This commit is contained in:
Eric Bower 2022-07-13 23:05:05 -04:00
parent c867fb74e9
commit 865f5c2054
No known key found for this signature in database
GPG key ID: 7A51A47D76D3FD02
2 changed files with 6 additions and 4 deletions

View file

@ -482,7 +482,7 @@ func StartApiServer() {
defer db.Close() defer db.Close()
logger := cfg.Logger logger := cfg.Logger
go CronDeleteExpiredPosts(db) go CronDeleteExpiredPosts(cfg, db)
staticRoutes := createStaticRoutes() staticRoutes := createStaticRoutes()
mainRoutes := createMainRoutes(staticRoutes) mainRoutes := createMainRoutes(staticRoutes)

View file

@ -6,7 +6,8 @@ import (
"git.sr.ht/~erock/wish/cms/db" "git.sr.ht/~erock/wish/cms/db"
) )
func deleteExpiredPosts(dbpool db.DB) error { func deleteExpiredPosts(cfg *ConfigSite, dbpool db.DB) error {
cfg.Logger.Infof("checking for expired posts")
now := time.Now() now := time.Now()
// delete posts that are older than three days // delete posts that are older than three days
expired := now.AddDate(0, 0, -3) expired := now.AddDate(0, 0, -3)
@ -20,6 +21,7 @@ func deleteExpiredPosts(dbpool db.DB) error {
postIds = append(postIds, post.ID) postIds = append(postIds, post.ID)
} }
cfg.Logger.Infof("deleteing (%d) expired posts", len(postIds))
err = dbpool.RemovePosts(postIds) err = dbpool.RemovePosts(postIds)
if err != nil { if err != nil {
return err return err
@ -28,9 +30,9 @@ func deleteExpiredPosts(dbpool db.DB) error {
return nil return nil
} }
func CronDeleteExpiredPosts(dbpool db.DB) { func CronDeleteExpiredPosts(cfg *ConfigSite, dbpool db.DB) {
for { for {
deleteExpiredPosts(dbpool) deleteExpiredPosts(cfg, dbpool)
time.Sleep(1 * time.Hour) time.Sleep(1 * time.Hour)
} }
} }