diff --git a/engine/db.go b/engine/db.go index 519b13a..6c30aef 100644 --- a/engine/db.go +++ b/engine/db.go @@ -7,6 +7,13 @@ import ( "fmt" ) +func postHandler(reportPostChan chan ReportPost, pool *pgxpool.Pool) { + for { // Write posts + v := <-reportPostChan + go writePost(pool, v) + } +} + func writePost(pool *pgxpool.Pool, reportpost ReportPost) { conn, err := pool.Acquire(context.Background()) if err != nil { diff --git a/engine/fedilogue.go b/engine/fedilogue.go index bc2beca..50076c5 100644 --- a/engine/fedilogue.go +++ b/engine/fedilogue.go @@ -7,6 +7,7 @@ import ( "regexp" "log" "github.com/microcosm-cc/bluemonday" + "runtime" ) // Current instances @@ -28,6 +29,10 @@ func main() { pool := get_db_pool() + for i := 0; i < settings.Database.Workers; i++ { + go postHandler(reportPostChan, pool) + } + p = bluemonday.NewPolicy() spaceReg = regexp.MustCompile(`\s+`) @@ -45,10 +50,7 @@ func main() { } go startctl(reportPostChan) - go webmain(reportPostChan) - for { // Write posts - v := <-reportPostChan - go writePost(pool, v) - } + + runtime.Goexit() }