66 lines
1.3 KiB
Go
Raw Normal View History

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