1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

fix(settings): updateSettingsFromFlags only if dataStore is new [EE-2397] (#6475)

This commit is contained in:
Marcelo Rydel 2022-01-28 09:28:34 -03:00 committed by GitHub
parent 0ad66510a9
commit edd5193100
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 42 deletions

View file

@ -23,21 +23,39 @@ type Service struct {
}
// NewService creates a new instance of a service
func NewService(snapshotInterval string, dataStore dataservices.DataStore, dockerSnapshotter portainer.DockerSnapshotter, kubernetesSnapshotter portainer.KubernetesSnapshotter, shutdownCtx context.Context) (*Service, error) {
snapshotFrequency, err := time.ParseDuration(snapshotInterval)
func NewService(snapshotIntervalFromFlag string, dataStore dataservices.DataStore, dockerSnapshotter portainer.DockerSnapshotter, kubernetesSnapshotter portainer.KubernetesSnapshotter, shutdownCtx context.Context) (*Service, error) {
snapshotFrequency, err := parseSnapshotFrequency(snapshotIntervalFromFlag, dataStore)
if err != nil {
return nil, err
}
return &Service{
dataStore: dataStore,
snapshotIntervalInSeconds: snapshotFrequency.Seconds(),
snapshotIntervalInSeconds: snapshotFrequency,
dockerSnapshotter: dockerSnapshotter,
kubernetesSnapshotter: kubernetesSnapshotter,
shutdownCtx: shutdownCtx,
}, nil
}
func parseSnapshotFrequency(snapshotInterval string, dataStore dataservices.DataStore) (float64, error) {
if snapshotInterval == "" {
settings, err := dataStore.Settings().Settings()
if err != nil {
return 0, err
}
snapshotInterval = settings.SnapshotInterval
if snapshotInterval == "" {
snapshotInterval = portainer.DefaultSnapshotInterval
}
}
snapshotFrequency, err := time.ParseDuration(snapshotInterval)
if err != nil {
return 0, err
}
return snapshotFrequency.Seconds(), nil
}
// Start will start a background routine to execute periodic snapshots of environments(endpoints)
func (service *Service) Start() {
if service.refreshSignal != nil {