mapserver/tileupdate/job.go

41 lines
719 B
Go
Raw Normal View History

2019-01-18 15:07:01 +03:00
package tileupdate
import (
2019-01-18 15:50:59 +03:00
"github.com/sirupsen/logrus"
"mapserver/app"
"time"
2019-01-18 15:07:01 +03:00
)
2019-01-18 15:50:59 +03:00
func Job(ctx *app.App) {
2019-01-21 13:13:00 +03:00
rstate := ctx.Config.RenderState
2019-01-18 15:07:01 +03:00
2019-01-18 15:50:59 +03:00
fields := logrus.Fields{
2019-01-21 13:13:00 +03:00
"lastmtime": rstate.LastMtime,
2019-01-18 15:50:59 +03:00
}
logrus.WithFields(fields).Info("Starting incremental update")
2019-01-18 15:07:01 +03:00
2019-01-18 15:50:59 +03:00
for true {
2019-01-21 13:13:00 +03:00
mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(rstate.LastMtime, 1000)
2019-01-18 15:07:01 +03:00
2019-01-18 15:50:59 +03:00
if err != nil {
panic(err)
}
2019-01-18 15:07:01 +03:00
2019-01-18 15:50:59 +03:00
for _, mb := range mblist {
2019-01-21 13:13:00 +03:00
if mb.Mtime > rstate.LastMtime {
rstate.LastMtime = mb.Mtime + 1
2019-01-18 15:50:59 +03:00
}
}
2019-01-18 15:07:01 +03:00
2019-01-21 12:53:58 +03:00
ctx.Config.Save()
2019-01-18 15:50:59 +03:00
fields = logrus.Fields{
2019-01-21 13:13:00 +03:00
"count": len(mblist),
"lastmtime": rstate.LastMtime,
2019-01-18 15:50:59 +03:00
}
logrus.WithFields(fields).Info("incremental update")
2019-01-18 15:07:01 +03:00
2019-01-18 15:50:59 +03:00
time.Sleep(5 * time.Second)
}
2019-01-18 15:07:01 +03:00
}