From 3d196ccf4168a282df0bf400155f370876949638 Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Mon, 14 Dec 2020 23:09:51 +0000 Subject: [PATCH] Added multiple post handlers + exiting the main goroutine --- engine/db.go | 7 +++++++ engine/fedilogue.go | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) 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() }