mapserver/server/tilerendererjob/incremental.go
Thomas Rudin bd630ef7d0 tile gc
2019-02-10 18:38:30 +01:00

69 lines
1.4 KiB
Go

package tilerendererjob
import (
"mapserver/app"
"mapserver/coords"
"mapserver/settings"
"time"
"github.com/sirupsen/logrus"
)
type IncrementalRenderEvent struct {
LastMtime int64 `json:"lastmtime"`
}
func incrementalRender(ctx *app.App, jobs chan *coords.TileCoords) {
lastMtime := ctx.Settings.GetInt64(settings.SETTING_LAST_MTIME, 0)
fields := logrus.Fields{
"LastMtime": lastMtime,
}
logrus.WithFields(fields).Info("Starting incremental rendering job")
for true {
start := time.Now()
result, err := ctx.BlockAccessor.FindMapBlocksByMtime(lastMtime, ctx.Config.RenderingFetchLimit, ctx.Config.Layers)
if err != nil {
panic(err)
}
if len(result.List) == 0 && !result.HasMore {
time.Sleep(5 * time.Second)
continue
}
tiles := renderMapblocks(ctx, jobs, result.List)
lastMtime = result.LastMtime
ctx.Settings.SetInt64(settings.SETTING_LAST_MTIME, lastMtime)
t := time.Now()
elapsed := t.Sub(start)
ev := IncrementalRenderEvent{
LastMtime: result.LastMtime,
}
ctx.WebEventbus.Emit("incremental-render-progress", &ev)
millisDiff := time.Now().Unix() - result.LastMtime
fields := logrus.Fields{
"mapblocks": len(result.List),
"tiles": tiles,
"elapsed": elapsed,
"lastMtime": result.LastMtime,
"secondsDiff": millisDiff / 1000,
}
logrus.WithFields(fields).Info("incremental rendering")
//tile gc
ctx.TileDB.GC()
}
}