Added multiple post handlers + exiting the main goroutine

This commit is contained in:
farhan 2020-12-14 23:09:51 +00:00
parent 8aff111336
commit 3d196ccf41
2 changed files with 14 additions and 5 deletions

View File

@ -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 {

View File

@ -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()
}