mapserver/tilerendererjob/incremental.go

69 lines
1.4 KiB
Go
Raw Permalink Normal View History

2019-01-24 17:56:37 +03:00
package tilerendererjob
import (
"mapserver/app"
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-02-20 12:10:00 +03:00
func incrementalRender(ctx *app.App) {
2019-01-24 17:56:37 +03:00
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-07-31 14:41:35 +03:00
result, err := ctx.MapBlockAccessor.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 {
2020-04-14 14:43:07 +03:00
renderingDuration, err := time.ParseDuration(ctx.Config.IncrementalRenderingTimer)
if err != nil {
panic(err)
}
time.Sleep(renderingDuration)
2019-01-24 17:56:37 +03:00
continue
}
2019-02-20 12:10:00 +03:00
tiles := renderMapblocks(ctx, result.List)
2019-02-08 10:14:22 +03:00
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-01-24 17:56:37 +03:00
fields := logrus.Fields{
2019-04-03 09:18:44 +03:00
"mapblocks": len(result.List),
"tiles": tiles,
"elapsed": elapsed,
"lastMtime": result.LastMtime,
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
}
}