forked from MTSR/mapserver
retire json config
This commit is contained in:
parent
eb793e4916
commit
98bab10ce4
@ -3,7 +3,6 @@ package app
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mapserver/coords"
|
|
||||||
"mapserver/layer"
|
"mapserver/layer"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -11,15 +10,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
EnableRendering bool `json:"enablerendering"`
|
EnableRendering bool `json:"enablerendering"`
|
||||||
Webdev bool `json:"webdev"`
|
Webdev bool `json:"webdev"`
|
||||||
WebApi *WebApiConfig `json:"webapi"`
|
WebApi *WebApiConfig `json:"webapi"`
|
||||||
RenderState *RenderStateType `json:"renderstate"`
|
Layers []layer.Layer `json:"layers"`
|
||||||
Layers []layer.Layer `json:"layers"`
|
RenderingFetchLimit int `json:"renderingfetchlimit"`
|
||||||
RenderingFetchLimit int `json:"renderingfetchlimit"`
|
RenderingJobs int `json:"renderingjobs"`
|
||||||
RenderingJobs int `json:"renderingjobs"`
|
RenderingQueue int `json:"renderingqueue"`
|
||||||
RenderingQueue int `json:"renderingqueue"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebApiConfig struct {
|
type WebApiConfig struct {
|
||||||
@ -30,20 +28,6 @@ type WebApiConfig struct {
|
|||||||
SecretKey string `json:"secretkey"`
|
SecretKey string `json:"secretkey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RenderStateType struct {
|
|
||||||
//Initial rendering flag (true=still active)
|
|
||||||
InitialRun bool `json:"initialrun"`
|
|
||||||
LegacyProcessed int `json:"legacyprocessed"`
|
|
||||||
|
|
||||||
//Last initial rendering coords
|
|
||||||
LastX int `json:"lastx"`
|
|
||||||
LastY int `json:"lasty"`
|
|
||||||
LastZ int `json:"lastz"`
|
|
||||||
|
|
||||||
//Last mtime of incremental rendering
|
|
||||||
LastMtime int64 `json:"lastmtime"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var lock sync.Mutex
|
var lock sync.Mutex
|
||||||
|
|
||||||
const ConfigFile = "mapserver.json"
|
const ConfigFile = "mapserver.json"
|
||||||
@ -79,14 +63,6 @@ func ParseConfig(filename string) (*Config, error) {
|
|||||||
SecretKey: RandStringRunes(16),
|
SecretKey: RandStringRunes(16),
|
||||||
}
|
}
|
||||||
|
|
||||||
rstate := RenderStateType{
|
|
||||||
InitialRun: true,
|
|
||||||
LastX: coords.MinCoord - 1,
|
|
||||||
LastY: coords.MinCoord - 1,
|
|
||||||
LastZ: coords.MinCoord - 1,
|
|
||||||
LastMtime: 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
layers := []layer.Layer{
|
layers := []layer.Layer{
|
||||||
layer.Layer{
|
layer.Layer{
|
||||||
Id: 0,
|
Id: 0,
|
||||||
@ -101,7 +77,6 @@ func ParseConfig(filename string) (*Config, error) {
|
|||||||
EnableRendering: true,
|
EnableRendering: true,
|
||||||
Webdev: false,
|
Webdev: false,
|
||||||
WebApi: &webapi,
|
WebApi: &webapi,
|
||||||
RenderState: &rstate,
|
|
||||||
Layers: layers,
|
Layers: layers,
|
||||||
RenderingFetchLimit: 1000,
|
RenderingFetchLimit: 1000,
|
||||||
RenderingJobs: runtime.NumCPU(),
|
RenderingJobs: runtime.NumCPU(),
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
"mapserver/settings"
|
"mapserver/settings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ func incrementalRender(ctx *app.App, jobs chan *coords.TileCoords) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lastMtime = result.LastMtime
|
lastMtime = result.LastMtime
|
||||||
ctx.Settings.GetInt64(settings.SETTING_LAST_MTIME, lastMtime)
|
ctx.Settings.SetInt64(settings.SETTING_LAST_MTIME, lastMtime)
|
||||||
|
|
||||||
tiles := renderMapblocks(ctx, jobs, result.List)
|
tiles := renderMapblocks(ctx, jobs, result.List)
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package tilerendererjob
|
package tilerendererjob
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"mapserver/app"
|
"mapserver/app"
|
||||||
"mapserver/settings"
|
|
||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
|
"mapserver/settings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InitialRenderEvent struct {
|
type InitialRenderEvent struct {
|
||||||
@ -21,7 +22,7 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fields := logrus.Fields{
|
fields := logrus.Fields{
|
||||||
"totalLegacyCount": totalLegacyCount
|
"totalLegacyCount": totalLegacyCount,
|
||||||
}
|
}
|
||||||
logrus.WithFields(fields).Info("Starting initial rendering job")
|
logrus.WithFields(fields).Info("Starting initial rendering job")
|
||||||
|
|
||||||
@ -40,6 +41,8 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
legacyProcessed := ctx.Settings.GetInt(settings.SETTING_LEGACY_PROCESSED, 0)
|
||||||
|
|
||||||
if len(result.List) == 0 && !result.HasMore {
|
if len(result.List) == 0 && !result.HasMore {
|
||||||
ctx.Settings.SetBool(settings.SETTING_INITIAL_RUN, false)
|
ctx.Settings.SetBool(settings.SETTING_INITIAL_RUN, false)
|
||||||
|
|
||||||
@ -50,7 +53,7 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) {
|
|||||||
ctx.WebEventbus.Emit("initial-render-progress", &ev)
|
ctx.WebEventbus.Emit("initial-render-progress", &ev)
|
||||||
|
|
||||||
fields := logrus.Fields{
|
fields := logrus.Fields{
|
||||||
"legacyblocks": rstate.LegacyProcessed,
|
"legacyblocks": legacyProcessed,
|
||||||
}
|
}
|
||||||
logrus.WithFields(fields).Info("initial rendering complete")
|
logrus.WithFields(fields).Info("initial rendering complete")
|
||||||
|
|
||||||
@ -60,19 +63,20 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) {
|
|||||||
tiles := renderMapblocks(ctx, jobs, result.List)
|
tiles := renderMapblocks(ctx, jobs, result.List)
|
||||||
|
|
||||||
lastcoords = result.LastPos
|
lastcoords = result.LastPos
|
||||||
rstate.LastMtime = result.LastMtime
|
ctx.Settings.SetInt64(settings.SETTING_LAST_MTIME, result.LastMtime)
|
||||||
|
|
||||||
//Save current positions of initial run
|
//Save current positions of initial run
|
||||||
rstate.LastX = lastcoords.X
|
ctx.Settings.SetInt(settings.SETTING_LASTX, lastcoords.X)
|
||||||
rstate.LastY = lastcoords.Y
|
ctx.Settings.SetInt(settings.SETTING_LASTY, lastcoords.Y)
|
||||||
rstate.LastZ = lastcoords.Z
|
ctx.Settings.SetInt(settings.SETTING_LASTZ, lastcoords.Z)
|
||||||
rstate.LegacyProcessed += result.UnfilteredCount
|
legacyProcessed += result.UnfilteredCount
|
||||||
ctx.Config.Save()
|
|
||||||
|
ctx.Settings.SetInt(settings.SETTING_LEGACY_PROCESSED, legacyProcessed)
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
elapsed := t.Sub(start)
|
elapsed := t.Sub(start)
|
||||||
|
|
||||||
progress := int(float64(rstate.LegacyProcessed) / float64(totalLegacyCount) * 100)
|
progress := int(float64(legacyProcessed) / float64(totalLegacyCount) * 100)
|
||||||
|
|
||||||
ev := InitialRenderEvent{
|
ev := InitialRenderEvent{
|
||||||
Progress: progress,
|
Progress: progress,
|
||||||
@ -83,7 +87,7 @@ func initialRender(ctx *app.App, jobs chan *coords.TileCoords) {
|
|||||||
fields := logrus.Fields{
|
fields := logrus.Fields{
|
||||||
"mapblocks": len(result.List),
|
"mapblocks": len(result.List),
|
||||||
"tiles": tiles,
|
"tiles": tiles,
|
||||||
"processed": rstate.LegacyProcessed,
|
"processed": legacyProcessed,
|
||||||
"progress%": progress,
|
"progress%": progress,
|
||||||
"X": lastcoords.X,
|
"X": lastcoords.X,
|
||||||
"Y": lastcoords.Y,
|
"Y": lastcoords.Y,
|
||||||
|
@ -3,18 +3,18 @@ package tilerendererjob
|
|||||||
import (
|
import (
|
||||||
"mapserver/app"
|
"mapserver/app"
|
||||||
"mapserver/coords"
|
"mapserver/coords"
|
||||||
|
"mapserver/settings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Job(ctx *app.App) {
|
func Job(ctx *app.App) {
|
||||||
|
|
||||||
rstate := ctx.Config.RenderState
|
|
||||||
jobs := make(chan *coords.TileCoords, ctx.Config.RenderingQueue)
|
jobs := make(chan *coords.TileCoords, ctx.Config.RenderingQueue)
|
||||||
|
|
||||||
for i := 0; i < ctx.Config.RenderingJobs; i++ {
|
for i := 0; i < ctx.Config.RenderingJobs; i++ {
|
||||||
go worker(ctx, jobs)
|
go worker(ctx, jobs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rstate.InitialRun {
|
if ctx.Settings.GetBool(settings.SETTING_INITIAL_RUN, true) {
|
||||||
//fast, unsafe mode
|
//fast, unsafe mode
|
||||||
err := ctx.Objectdb.EnableSpeedSafetyTradeoff(true)
|
err := ctx.Objectdb.EnableSpeedSafetyTradeoff(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user