1
0
forked from MTSR/mapserver

mapdb stub

This commit is contained in:
NatureFreshMilk 2019-01-18 13:50:59 +01:00
parent 49a7de02fc
commit 08407ce0da
6 changed files with 67 additions and 40 deletions

View File

@ -2,14 +2,14 @@ package main
import (
"encoding/json"
"fmt"
"github.com/sirupsen/logrus"
"mapserver/app"
"mapserver/initialrenderer"
"mapserver/layerconfig"
"mapserver/params"
"mapserver/web"
"mapserver/tileupdate"
"fmt"
"mapserver/web"
)
func main() {

View File

@ -29,7 +29,7 @@ func (a *MapBlockAccessor) Update(pos coords.MapBlockCoords, mb *mapblockparser.
a.c.Set(key, mb, cache.DefaultExpiration)
}
func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*mapblockparser.MapBlock, error){
func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*mapblockparser.MapBlock, error) {
blocks, err := a.accessor.FindLatestBlocks(mintime, limit)
if err != nil {
@ -38,7 +38,7 @@ func (a *MapBlockAccessor) FindLatestMapBlocks(mintime int64, limit int) ([]*map
mblist := make([]*mapblockparser.MapBlock, 0)
for _, block := range(blocks) {
for _, block := range blocks {
key := getKey(block.Pos)
mapblock, err := mapblockparser.Parse(block.Data, block.Mtime)

27
mapdb/accessor.go Normal file
View File

@ -0,0 +1,27 @@
package mapdb
import (
"mapserver/coords"
)
type MapData struct {
//mapblock position
MBPos coords.MapBlockCoords
//block position
X, Y, Z int
Type string
Data string
Mtime int64
}
type SearchQuery struct {
//block position (not mapblock)
Pos1, Pos2 coords.MapBlockCoords
Type string
}
type DBAccessor interface {
Migrate() error
GetMapData(q SearchQuery) ([]MapData, error)
SetMapData(pos coords.MapBlockCoords, data []MapData) error
}

View File

@ -1,12 +1,12 @@
package tileupdate
import (
"mapserver/app"
"github.com/sirupsen/logrus"
"mapserver/app"
"time"
)
func Job(ctx *app.App){
func Job(ctx *app.App) {
t := time.Now().Unix()
fields := logrus.Fields{
@ -21,18 +21,18 @@ func Job(ctx *app.App){
panic(err)
}
for _, mb := range mblist {
if mb.Mtime > t {
t = mb.Mtime + 1
}
}
fields = logrus.Fields{
"count": len(mblist),
"time": t,
}
logrus.WithFields(fields).Info("incremental update")
for _, mb := range(mblist) {
if mb.Mtime > t {
t = mb.Mtime+1
}
}
time.Sleep(5 * time.Second)
}
}