mirror of
https://github.com/datarhei/core.git
synced 2025-09-26 20:11:29 +08:00
Fix config timestamps
created_at represents the time when the configuration has been persisted to disk. loaded_at represents the time when the configuration has actually been used. If created_at is larger than loaded_at, then the Core needs a reload in order to apply the latest configuration. if created_at is lower than laoded_at, then the Core applied the latest configuration. The value of updated_at is irrelevant and shouldn't be used.
This commit is contained in:
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
cfgstore "github.com/datarhei/core/v16/config/store"
|
||||
cfgvars "github.com/datarhei/core/v16/config/vars"
|
||||
@@ -71,6 +72,10 @@ func (p *ConfigHandler) Set(c echo.Context) error {
|
||||
}
|
||||
|
||||
cfg := p.store.Get()
|
||||
cfgActive := p.store.GetActive()
|
||||
|
||||
// Copy the timestamp of when this config has been used
|
||||
cfg.LoadedAt = cfgActive.LoadedAt
|
||||
|
||||
// For each version, set the current config as default config value. This will
|
||||
// allow to set a partial config without destroying the other values.
|
||||
@@ -119,6 +124,9 @@ func (p *ConfigHandler) Set(c echo.Context) error {
|
||||
return api.Err(http.StatusBadRequest, "Invalid config version", "version %d", version.Version)
|
||||
}
|
||||
|
||||
cfg.CreatedAt = time.Now()
|
||||
cfg.UpdatedAt = cfg.CreatedAt
|
||||
|
||||
// Now we make a copy from the config and merge it with the environment
|
||||
// variables. If this configuration is valid, we will store the un-merged
|
||||
// one to disk.
|
||||
|
Reference in New Issue
Block a user