Use a more general db client factory approach.

This commit is contained in:
Sascha L. Teichmann
2022-03-01 14:47:14 +01:00
parent 834c8a9bc6
commit c507663826
9 changed files with 99 additions and 53 deletions

View File

@ -118,7 +118,11 @@ func main() {
colors.TransparentDim = common.Clamp32f(
float32(transparentDim/100.0), 0.0, 100.0)
dbcc := common.CreateDBClientCreator(redisHost, redisPort)
dbcf, err := common.CreateDBClientFactory(redisHost, redisPort)
if err != nil {
log.Fatalf("error: %v\n", err)
}
defer dbcf.Close()
var allowedUpdateIps []net.IP
if allowedUpdateIps, err = ipsFromHosts(updateHosts); err != nil {
@ -127,7 +131,7 @@ func main() {
tu := newTileUpdater(
mapDir,
dbcc,
dbcf,
allowedUpdateIps,
colors, bg,
yMin, yMax,

View File

@ -38,7 +38,7 @@ type tileUpdater struct {
changes map[xz]struct{}
btu baseTilesUpdates
mapDir string
dbcc common.DBClientCreator
dbcf common.DBClientFactory
ips []net.IP
colors *common.Colors
bg color.RGBA
@ -82,7 +82,7 @@ func (c xz) parent() xzm {
func newTileUpdater(
mapDir string,
dbcc common.DBClientCreator,
dbcf common.DBClientFactory,
ips []net.IP,
colors *common.Colors,
bg color.RGBA,
@ -94,7 +94,7 @@ func newTileUpdater(
tu := tileUpdater{
btu: btu,
mapDir: mapDir,
dbcc: dbcc,
dbcf: dbcf,
ips: ips,
changes: map[xz]struct{}{},
colors: colors,
@ -262,10 +262,11 @@ func (tu *tileUpdater) doUpdates() {
for i, n := 0, common.Min(tu.workers, len(changes)); i < n; i++ {
var client common.DBClient
var err error
if client, err = tu.dbcc(); err != nil {
if client, err = tu.dbcf.Create(); err != nil {
log.Printf("WARN: Cannot connect to redis server: %s\n", err)
continue
}
btc := common.NewBaseTileCreator(
client, tu.colors, tu.bg,
tu.yMin, tu.yMax,