aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulio Capote <jcapote@gmail.com>2023-01-08 13:28:30 +0000
committerJulio Capote <jcapote@gmail.com>2023-01-08 13:28:30 +0000
commit82452d909a8c4ed1147817a1e23d20b090685d2c (patch)
tree477ffc1d2eadd59c49ceaec0e1538dcbdc14b13a
parent14963269dc63bf038163a851e521d6815ab5f514 (diff)
downloadcommunique-82452d909a8c4ed1147817a1e23d20b090685d2c.tar.gz
async GC in background
-rw-r--r--TODO2
-rw-r--r--main.go20
2 files changed, 14 insertions, 8 deletions
diff --git a/TODO b/TODO
index 4076b5f..a398cc4 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,5 @@
* graceful shutdown
-* outbox delivery
+* attachment support
* namespace everything to /c/ so apache can 404 requests to / instead of us
* outbox return latest 20 posts only
* make badger GC run continously
diff --git a/main.go b/main.go
index 261c247..b4ea011 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,7 @@ package main
import (
"sync"
+ "time"
"git.capotej.com/capotej/communique/cgi"
"git.capotej.com/capotej/communique/config"
@@ -41,13 +42,18 @@ func main() {
}
defer db.Close()
- log.With("type", "db").Debug("Running GC")
- err = db.RunValueLogGC(0.5)
- if err == badger.ErrNoRewrite {
- log.With("type", "db").Debug("Nothing to GC")
- } else {
- log.Fatal(err)
- }
+ ticker := time.NewTicker(5 * time.Minute)
+ defer ticker.Stop()
+
+ go func() {
+ for {
+ select {
+ case _ = <-ticker.C:
+ log.With("type", "db").Debug("Running GC")
+ db.RunValueLogGC(0.7)
+ }
+ }
+ }()
// Persister
persister := models.NewPersister(log, db)