mapserver/tilerendererjob/initial.go

66 lines
1.3 KiB
Go
Raw Normal View History

2019-01-24 17:56:37 +03:00
package tilerendererjob
import (
"mapserver/app"
2019-02-07 20:44:40 +03:00
"mapserver/settings"
2019-01-24 17:56:37 +03:00
"time"
2019-02-07 20:44:40 +03:00
"github.com/sirupsen/logrus"
2019-01-24 17:56:37 +03:00
)
2019-02-01 16:50:39 +03:00
type InitialRenderEvent struct {
2019-02-15 10:58:04 +03:00
Progress float64 `json:"progress"`
2019-02-01 16:50:39 +03:00
}
2019-02-20 12:10:00 +03:00
func initialRender(ctx *app.App) {
2019-02-15 10:58:04 +03:00
logrus.Info("Starting initial rendering job")
2019-01-24 17:56:37 +03:00
for true {
start := time.Now()
2019-07-31 14:41:35 +03:00
result, err := ctx.MapBlockAccessor.FindNextLegacyBlocks(ctx.Settings, ctx.Config.Layers, ctx.Config.RenderingFetchLimit)
2019-01-24 17:56:37 +03:00
if err != nil {
logrus.Error("Error in initial rendering run, trying to continue: " + err.Error())
continue
2019-01-24 17:56:37 +03:00
}
if len(result.List) == 0 && !result.HasMore {
2019-02-07 11:58:10 +03:00
ctx.Settings.SetBool(settings.SETTING_INITIAL_RUN, false)
2019-01-24 17:56:37 +03:00
2019-02-01 16:50:39 +03:00
ev := InitialRenderEvent{
2019-02-15 10:58:04 +03:00
Progress: 1,
2019-02-01 16:50:39 +03:00
}
ctx.WebEventbus.Emit("initial-render-progress", &ev)
2019-02-15 10:58:04 +03:00
logrus.Info("initial rendering complete")
2019-01-24 17:56:37 +03:00
return
}
2019-02-20 12:10:00 +03:00
tiles := renderMapblocks(ctx, 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 := InitialRenderEvent{
2019-02-15 10:58:04 +03:00
Progress: result.Progress,
2019-02-01 16:50:39 +03:00
}
ctx.WebEventbus.Emit("initial-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,
2019-02-15 10:58:04 +03:00
"progress%": int(result.Progress * 100),
2019-01-24 17:56:37 +03:00
"elapsed": elapsed,
}
logrus.WithFields(fields).Info("Initial rendering")
2019-02-10 20:38:30 +03:00
//tile gc
ctx.TileDB.GC()
2019-01-24 17:56:37 +03:00
}
}