Use db abstraction in webmapper.

This commit is contained in:
Sascha L. Teichmann 2022-02-27 21:31:55 +01:00
parent 4f7fedf0b9
commit ae230d5abf
2 changed files with 31 additions and 41 deletions

View File

@ -10,7 +10,6 @@ import (
"log"
"net"
"net/http"
"strings"
"bitbucket.org/s_l_teichmann/mtsatellite/common"
@ -107,6 +106,7 @@ func main() {
}
if redisHost != "" {
var colors *common.Colors
var err error
if colors, err = common.ParseColors(colorsFile); err != nil {
@ -114,12 +114,8 @@ func main() {
}
colors.TransparentDim = common.Clamp32f(
float32(transparentDim/100.0), 0.0, 100.0)
var redisAddress string
if strings.ContainsRune(redisHost, '/') {
redisAddress = redisHost
} else {
redisAddress = fmt.Sprintf("%s:%d", redisHost, redisPort)
}
dbcc := common.CreateDBClientCreator(redisHost, redisPort)
var allowedUpdateIps []net.IP
if allowedUpdateIps, err = ipsFromHosts(updateHosts); err != nil {
@ -128,7 +124,7 @@ func main() {
tu := newTileUpdater(
mapDir,
redisAddress,
dbcc,
allowedUpdateIps,
colors, bg,
yMin, yMax,

View File

@ -35,7 +35,7 @@ type tileUpdater struct {
changes map[xz]struct{}
btu baseTilesUpdates
mapDir string
redisAddress string
dbcc common.DBClientCreator
ips []net.IP
colors *common.Colors
bg color.RGBA
@ -78,7 +78,8 @@ func (c xz) parent() xzm {
}
func newTileUpdater(
mapDir, redisAddress string,
mapDir string,
dbcc common.DBClientCreator,
ips []net.IP,
colors *common.Colors,
bg color.RGBA,
@ -90,7 +91,7 @@ func newTileUpdater(
tu := tileUpdater{
btu: btu,
mapDir: mapDir,
redisAddress: redisAddress,
dbcc: dbcc,
ips: ips,
changes: map[xz]struct{}{},
colors: colors,
@ -196,17 +197,10 @@ func (tu *tileUpdater) doUpdates() {
jobs := make(chan *xzc)
var done sync.WaitGroup
var proto string
if strings.ContainsRune(tu.redisAddress, '/') {
proto = "unix"
} else {
proto = "tcp"
}
for i, n := 0, common.Min(tu.workers, len(changes)); i < n; i++ {
var client *common.RedisClient
var client common.DBClient
var err error
if client, err = common.NewRedisClient(proto, tu.redisAddress); err != nil {
if client, err = tu.dbcc(); err != nil {
log.Printf("WARN: Cannot connect to redis server: %s\n", err)
continue
}