1
0
forked from MTSR/mapserver
mapserver/server/tilerendererjob/incremental.go

61 lines
1.2 KiB
Go
Raw Normal View History

2019-01-24 17:56:37 +03:00
package tilerendererjob
import (
"mapserver/app"
"mapserver/coords"
2019-02-07 11:11:11 +03:00
"mapserver/settings"
2019-01-24 17:56:37 +03:00
"time"
2019-02-07 20:44:40 +03:00
2019-01-25 19:57:38 +03:00
"github.com/sirupsen/logrus"
2019-01-24 17:56:37 +03:00
)
2019-02-01 16:50:39 +03:00
type IncrementalRenderEvent struct {
LastMtime int64 `json:"lastmtime"`
}
2019-01-24 17:56:37 +03:00
func incrementalRender(ctx *app.App, jobs chan *coords.TileCoords) {
2019-02-07 11:11:11 +03:00
lastMtime := ctx.Settings.GetInt64(settings.SETTING_LAST_MTIME, 0)
2019-01-24 17:56:37 +03:00
fields := logrus.Fields{
2019-02-07 10:35:57 +03:00
"LastMtime": lastMtime,
2019-01-24 17:56:37 +03:00
}
logrus.WithFields(fields).Info("Starting incremental rendering job")
for true {
start := time.Now()
2019-02-07 10:35:57 +03:00
result, err := ctx.BlockAccessor.FindMapBlocksByMtime(lastMtime, ctx.Config.RenderingFetchLimit, ctx.Config.Layers)
2019-01-24 17:56:37 +03:00
if err != nil {
panic(err)
}
2019-01-27 20:54:09 +03:00
if len(result.List) == 0 && !result.HasMore {
2019-01-24 17:56:37 +03:00
time.Sleep(5 * time.Second)
continue
}
2019-02-07 10:35:57 +03:00
lastMtime = result.LastMtime
2019-02-07 20:44:40 +03:00
ctx.Settings.SetInt64(settings.SETTING_LAST_MTIME, lastMtime)
2019-01-27 20:54:09 +03:00
2019-01-24 18:33:54 +03:00
tiles := renderMapblocks(ctx, jobs, result.List)
2019-01-24 17:56:37 +03:00
t := time.Now()
elapsed := t.Sub(start)
2019-02-01 16:50:39 +03:00
ev := IncrementalRenderEvent{
LastMtime: result.LastMtime,
}
ctx.WebEventbus.Emit("incremental-render-progress", &ev)
2019-01-24 17:56:37 +03:00
fields := logrus.Fields{
2019-01-24 18:33:54 +03:00
"mapblocks": len(result.List),
"tiles": tiles,
"elapsed": elapsed,
2019-01-24 17:56:37 +03:00
}
logrus.WithFields(fields).Info("incremental rendering")
}
}