mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-15 23:00:19 +01:00
Use db abstraction in webmapper.
This commit is contained in:
parent
4f7fedf0b9
commit
ae230d5abf
|
@ -10,7 +10,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"bitbucket.org/s_l_teichmann/mtsatellite/common"
|
"bitbucket.org/s_l_teichmann/mtsatellite/common"
|
||||||
|
|
||||||
|
@ -107,6 +106,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if redisHost != "" {
|
if redisHost != "" {
|
||||||
|
|
||||||
var colors *common.Colors
|
var colors *common.Colors
|
||||||
var err error
|
var err error
|
||||||
if colors, err = common.ParseColors(colorsFile); err != nil {
|
if colors, err = common.ParseColors(colorsFile); err != nil {
|
||||||
|
@ -114,12 +114,8 @@ func main() {
|
||||||
}
|
}
|
||||||
colors.TransparentDim = common.Clamp32f(
|
colors.TransparentDim = common.Clamp32f(
|
||||||
float32(transparentDim/100.0), 0.0, 100.0)
|
float32(transparentDim/100.0), 0.0, 100.0)
|
||||||
var redisAddress string
|
|
||||||
if strings.ContainsRune(redisHost, '/') {
|
dbcc := common.CreateDBClientCreator(redisHost, redisPort)
|
||||||
redisAddress = redisHost
|
|
||||||
} else {
|
|
||||||
redisAddress = fmt.Sprintf("%s:%d", redisHost, redisPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
var allowedUpdateIps []net.IP
|
var allowedUpdateIps []net.IP
|
||||||
if allowedUpdateIps, err = ipsFromHosts(updateHosts); err != nil {
|
if allowedUpdateIps, err = ipsFromHosts(updateHosts); err != nil {
|
||||||
|
@ -128,7 +124,7 @@ func main() {
|
||||||
|
|
||||||
tu := newTileUpdater(
|
tu := newTileUpdater(
|
||||||
mapDir,
|
mapDir,
|
||||||
redisAddress,
|
dbcc,
|
||||||
allowedUpdateIps,
|
allowedUpdateIps,
|
||||||
colors, bg,
|
colors, bg,
|
||||||
yMin, yMax,
|
yMin, yMax,
|
||||||
|
|
|
@ -35,7 +35,7 @@ type tileUpdater struct {
|
||||||
changes map[xz]struct{}
|
changes map[xz]struct{}
|
||||||
btu baseTilesUpdates
|
btu baseTilesUpdates
|
||||||
mapDir string
|
mapDir string
|
||||||
redisAddress string
|
dbcc common.DBClientCreator
|
||||||
ips []net.IP
|
ips []net.IP
|
||||||
colors *common.Colors
|
colors *common.Colors
|
||||||
bg color.RGBA
|
bg color.RGBA
|
||||||
|
@ -78,7 +78,8 @@ func (c xz) parent() xzm {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTileUpdater(
|
func newTileUpdater(
|
||||||
mapDir, redisAddress string,
|
mapDir string,
|
||||||
|
dbcc common.DBClientCreator,
|
||||||
ips []net.IP,
|
ips []net.IP,
|
||||||
colors *common.Colors,
|
colors *common.Colors,
|
||||||
bg color.RGBA,
|
bg color.RGBA,
|
||||||
|
@ -90,7 +91,7 @@ func newTileUpdater(
|
||||||
tu := tileUpdater{
|
tu := tileUpdater{
|
||||||
btu: btu,
|
btu: btu,
|
||||||
mapDir: mapDir,
|
mapDir: mapDir,
|
||||||
redisAddress: redisAddress,
|
dbcc: dbcc,
|
||||||
ips: ips,
|
ips: ips,
|
||||||
changes: map[xz]struct{}{},
|
changes: map[xz]struct{}{},
|
||||||
colors: colors,
|
colors: colors,
|
||||||
|
@ -196,17 +197,10 @@ func (tu *tileUpdater) doUpdates() {
|
||||||
jobs := make(chan *xzc)
|
jobs := make(chan *xzc)
|
||||||
var done sync.WaitGroup
|
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++ {
|
for i, n := 0, common.Min(tu.workers, len(changes)); i < n; i++ {
|
||||||
var client *common.RedisClient
|
var client common.DBClient
|
||||||
var err error
|
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)
|
log.Printf("WARN: Cannot connect to redis server: %s\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user