mapserver/server/tilerendererjob/incremental.go
2019-02-01 14:50:39 +01:00

60 lines
1.2 KiB
Go

package tilerendererjob
import (
"mapserver/app"
"mapserver/coords"
"time"
"github.com/sirupsen/logrus"
)
type IncrementalRenderEvent struct {
LastMtime int64 `json:"lastmtime"`
}
func incrementalRender(ctx *app.App, jobs chan *coords.TileCoords) {
rstate := ctx.Config.RenderState
fields := logrus.Fields{
"LastMtime": rstate.LastMtime,
}
logrus.WithFields(fields).Info("Starting incremental rendering job")
for true {
start := time.Now()
result, err := ctx.BlockAccessor.FindMapBlocksByMtime(rstate.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
}
rstate.LastMtime = result.LastMtime
ctx.Config.Save()
tiles := renderMapblocks(ctx, jobs, result.List)
t := time.Now()
elapsed := t.Sub(start)
ev := IncrementalRenderEvent{
LastMtime: result.LastMtime,
}
ctx.WebEventbus.Emit("incremental-render-progress", &ev)
fields := logrus.Fields{
"mapblocks": len(result.List),
"tiles": tiles,
"elapsed": elapsed,
}
logrus.WithFields(fields).Info("incremental rendering")
}
}