forked from picosh/pico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.go
39 lines (32 loc) · 740 Bytes
/
cron.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package pastes
import (
"time"
"github.com/picosh/pico/db"
"github.com/picosh/pico/shared"
)
func deleteExpiredPosts(cfg *shared.ConfigSite, dbpool db.DB) error {
cfg.Logger.Infof("checking for expired posts")
posts, err := dbpool.FindExpiredPosts(cfg.Space)
if err != nil {
return err
}
postIds := []string{}
for _, post := range posts {
postIds = append(postIds, post.ID)
}
cfg.Logger.Infof("deleting (%d) expired posts", len(postIds))
err = dbpool.RemovePosts(postIds)
if err != nil {
return err
}
return nil
}
func CronDeleteExpiredPosts(cfg *shared.ConfigSite, dbpool db.DB) {
for {
err := deleteExpiredPosts(cfg, dbpool)
if err != nil {
cfg.Logger.Error(err)
}
time.Sleep(1 * time.Minute)
}
}