Added multiple post handlers + exiting the main goroutine
This commit is contained in:
parent
8aff111336
commit
3d196ccf41
@ -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 {
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user