repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

pico / pastes
Eric Bower · 31 May 24

cron.go

 1package pastes
 2
 3import (
 4	"time"
 5
 6	"github.com/picosh/pico/db"
 7	"github.com/picosh/pico/shared"
 8)
 9
10func deleteExpiredPosts(cfg *shared.ConfigSite, dbpool db.DB) error {
11	cfg.Logger.Info("checking for expired posts")
12	posts, err := dbpool.FindExpiredPosts(cfg.Space)
13	if err != nil {
14		return err
15	}
16
17	postIds := []string{}
18	for _, post := range posts {
19		postIds = append(postIds, post.ID)
20	}
21
22	cfg.Logger.Info("deleting expired posts", "len", len(postIds))
23	err = dbpool.RemovePosts(postIds)
24	if err != nil {
25		return err
26	}
27
28	return nil
29}
30
31func CronDeleteExpiredPosts(cfg *shared.ConfigSite, dbpool db.DB) {
32	for {
33		err := deleteExpiredPosts(cfg, dbpool)
34		if err != nil {
35			cfg.Logger.Error(err.Error())
36		}
37		time.Sleep(12 * time.Hour)
38	}
39}