mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-13 05:40:20 +01:00
Use db abstraction in webmapper.
This commit is contained in:
parent
4f7fedf0b9
commit
ae230d5abf
|
@ -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,
|
||||
|
|
|
@ -32,18 +32,18 @@ type baseTilesUpdates interface {
|
|||
}
|
||||
|
||||
type tileUpdater struct {
|
||||
changes map[xz]struct{}
|
||||
btu baseTilesUpdates
|
||||
mapDir string
|
||||
redisAddress string
|
||||
ips []net.IP
|
||||
colors *common.Colors
|
||||
bg color.RGBA
|
||||
yMin, yMax int16
|
||||
workers int
|
||||
transparent bool
|
||||
cond *sync.Cond
|
||||
mu sync.Mutex
|
||||
changes map[xz]struct{}
|
||||
btu baseTilesUpdates
|
||||
mapDir string
|
||||
dbcc common.DBClientCreator
|
||||
ips []net.IP
|
||||
colors *common.Colors
|
||||
bg color.RGBA
|
||||
yMin, yMax int16
|
||||
workers int
|
||||
transparent bool
|
||||
cond *sync.Cond
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
type xz struct {
|
||||
|
@ -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,
|
||||
|
@ -88,17 +89,17 @@ func newTileUpdater(
|
|||
btu baseTilesUpdates) *tileUpdater {
|
||||
|
||||
tu := tileUpdater{
|
||||
btu: btu,
|
||||
mapDir: mapDir,
|
||||
redisAddress: redisAddress,
|
||||
ips: ips,
|
||||
changes: map[xz]struct{}{},
|
||||
colors: colors,
|
||||
bg: bg,
|
||||
yMin: int16(yMin),
|
||||
yMax: int16(yMax),
|
||||
transparent: transparent,
|
||||
workers: workers}
|
||||
btu: btu,
|
||||
mapDir: mapDir,
|
||||
dbcc: dbcc,
|
||||
ips: ips,
|
||||
changes: map[xz]struct{}{},
|
||||
colors: colors,
|
||||
bg: bg,
|
||||
yMin: int16(yMin),
|
||||
yMax: int16(yMax),
|
||||
transparent: transparent,
|
||||
workers: workers}
|
||||
tu.cond = sync.NewCond(&tu.mu)
|
||||
return &tu
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user