mapserver/server/tilerendererjob/incremental.go

69 lines
1.4 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-08 10:14:22 +03:00
tiles := renderMapblocks(ctx, jobs, result.List)
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 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-02-08 19:45:16 +03:00
millisDiff := time.Now().Unix() - result.LastMtime
2019-01-24 17:56:37 +03:00
fields := logrus.Fields{
2019-02-08 19:45:16 +03:00
"mapblocks": len(result.List),
"tiles": tiles,
"elapsed": elapsed,
"lastMtime": result.LastMtime,
"secondsDiff": millisDiff / 1000,
2019-01-24 17:56:37 +03:00
}
logrus.WithFields(fields).Info("incremental rendering")
2019-02-10 20:38:30 +03:00
//tile gc
ctx.TileDB.GC()
2019-01-24 17:56:37 +03:00
}
}