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:
Ingo Oppermann
2023-01-19 16:13:53 +01:00
parent 311defb27c
commit e374f83377
4 changed files with 17 additions and 13 deletions

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"time"
"github.com/datarhei/core/v16/config"
v1 "github.com/datarhei/core/v16/config/v1"
@@ -57,14 +56,10 @@ func (c *jsonStore) Set(d *config.Config) error {
data := d.Clone()
data.CreatedAt = time.Now()
if err := c.store(data); err != nil {
return fmt.Errorf("failed to write JSON to '%s': %w", c.path, err)
}
data.UpdatedAt = time.Now()
c.data["base"] = data
return nil
@@ -89,7 +84,9 @@ func (c *jsonStore) SetActive(d *config.Config) error {
return fmt.Errorf("configuration data has errors after validation")
}
c.data["merged"] = d.Clone()
data := d.Clone()
c.data["merged"] = data
return nil
}
@@ -129,15 +126,12 @@ func (c *jsonStore) load(cfg *config.Config) error {
cfg.Data = *data
cfg.LoadedAt = time.Now()
cfg.UpdatedAt = cfg.LoadedAt
cfg.UpdatedAt = cfg.CreatedAt
return nil
}
func (c *jsonStore) store(data *config.Config) error {
data.CreatedAt = time.Now()
if len(c.path) == 0 {
return nil
}