chore(cron): add some logging
This commit is contained in:
parent
c867fb74e9
commit
865f5c2054
2 changed files with 6 additions and 4 deletions
|
@ -482,7 +482,7 @@ func StartApiServer() {
|
|||
defer db.Close()
|
||||
logger := cfg.Logger
|
||||
|
||||
go CronDeleteExpiredPosts(db)
|
||||
go CronDeleteExpiredPosts(cfg, db)
|
||||
|
||||
staticRoutes := createStaticRoutes()
|
||||
mainRoutes := createMainRoutes(staticRoutes)
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
"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()
|
||||
// delete posts that are older than three days
|
||||
expired := now.AddDate(0, 0, -3)
|
||||
|
@ -20,6 +21,7 @@ func deleteExpiredPosts(dbpool db.DB) error {
|
|||
postIds = append(postIds, post.ID)
|
||||
}
|
||||
|
||||
cfg.Logger.Infof("deleteing (%d) expired posts", len(postIds))
|
||||
err = dbpool.RemovePosts(postIds)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -28,9 +30,9 @@ func deleteExpiredPosts(dbpool db.DB) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func CronDeleteExpiredPosts(dbpool db.DB) {
|
||||
func CronDeleteExpiredPosts(cfg *ConfigSite, dbpool db.DB) {
|
||||
for {
|
||||
deleteExpiredPosts(dbpool)
|
||||
deleteExpiredPosts(cfg, dbpool)
|
||||
time.Sleep(1 * time.Hour)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue