Skip to content

Commit dc9ddae

Browse files
FIX (copying): Fix persisting same interval over copying
1 parent a409c8c commit dc9ddae

File tree

4 files changed

+39
-29
lines changed

4 files changed

+39
-29
lines changed

backend/cmd/main.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"postgresus-backend/internal/features/disk"
2121
healthcheck_attempt "postgresus-backend/internal/features/healthcheck/attempt"
2222
healthcheck_config "postgresus-backend/internal/features/healthcheck/config"
23-
postgres_monitoring_collectors "postgresus-backend/internal/features/monitoring/postgres/collectors"
2423
postgres_monitoring_metrics "postgresus-backend/internal/features/monitoring/postgres/metrics"
2524
postgres_monitoring_settings "postgresus-backend/internal/features/monitoring/postgres/settings"
2625
"postgresus-backend/internal/features/notifiers"
@@ -210,10 +209,6 @@ func runBackgroundTasks(log *slog.Logger) {
210209
go runWithPanicLogging(log, "postgres monitoring metrics background service", func() {
211210
postgres_monitoring_metrics.GetPostgresMonitoringMetricsBackgroundService().Run()
212211
})
213-
214-
go runWithPanicLogging(log, "postgres monitoring collectors background service", func() {
215-
postgres_monitoring_collectors.GetDbMonitoringBackgroundService().Run()
216-
})
217212
}
218213

219214
func runWithPanicLogging(log *slog.Logger, serviceName string, fn func()) {

backend/internal/features/backups/config/model.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,18 @@ func (b *BackupConfig) Validate() error {
9090

9191
return nil
9292
}
93+
94+
func (b *BackupConfig) Copy(newDatabaseID uuid.UUID) *BackupConfig {
95+
return &BackupConfig{
96+
DatabaseID: newDatabaseID,
97+
IsBackupsEnabled: b.IsBackupsEnabled,
98+
StorePeriod: b.StorePeriod,
99+
BackupIntervalID: uuid.Nil,
100+
BackupInterval: b.BackupInterval.Copy(),
101+
StorageID: b.StorageID,
102+
SendNotificationsOn: b.SendNotificationsOn,
103+
IsRetryIfFailed: b.IsRetryIfFailed,
104+
MaxFailedTriesCount: b.MaxFailedTriesCount,
105+
CpuCount: b.CpuCount,
106+
}
107+
}

backend/internal/features/backups/config/service.go

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ func (s *BackupConfigService) GetBackupConfigsWithEnabledBackups() ([]*BackupCon
130130
return s.backupConfigRepository.GetWithEnabledBackups()
131131
}
132132

133+
func (s *BackupConfigService) OnDatabaseCopied(originalDatabaseID, newDatabaseID uuid.UUID) {
134+
originalConfig, err := s.GetBackupConfigByDbId(originalDatabaseID)
135+
if err != nil {
136+
return
137+
}
138+
139+
newConfig := originalConfig.Copy(newDatabaseID)
140+
141+
_, err = s.SaveBackupConfig(newConfig)
142+
if err != nil {
143+
return
144+
}
145+
}
146+
133147
func (s *BackupConfigService) initializeDefaultConfig(
134148
databaseID uuid.UUID,
135149
) error {
@@ -164,27 +178,3 @@ func storageIDsEqual(id1, id2 *uuid.UUID) bool {
164178
}
165179
return *id1 == *id2
166180
}
167-
168-
func (s *BackupConfigService) OnDatabaseCopied(originalDatabaseID, newDatabaseID uuid.UUID) {
169-
originalConfig, err := s.GetBackupConfigByDbId(originalDatabaseID)
170-
if err != nil {
171-
return
172-
}
173-
174-
newConfig := &BackupConfig{
175-
DatabaseID: newDatabaseID,
176-
IsBackupsEnabled: originalConfig.IsBackupsEnabled,
177-
StorePeriod: originalConfig.StorePeriod,
178-
BackupIntervalID: originalConfig.BackupIntervalID,
179-
StorageID: originalConfig.StorageID,
180-
SendNotificationsOn: originalConfig.SendNotificationsOn,
181-
IsRetryIfFailed: originalConfig.IsRetryIfFailed,
182-
MaxFailedTriesCount: originalConfig.MaxFailedTriesCount,
183-
CpuCount: originalConfig.CpuCount,
184-
}
185-
186-
_, err = s.SaveBackupConfig(newConfig)
187-
if err != nil {
188-
return
189-
}
190-
}

backend/internal/features/intervals/model.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ func (i *Interval) ShouldTriggerBackup(now time.Time, lastBackupTime *time.Time)
6464
}
6565
}
6666

67+
func (i *Interval) Copy() *Interval {
68+
return &Interval{
69+
ID: uuid.Nil,
70+
Interval: i.Interval,
71+
TimeOfDay: i.TimeOfDay,
72+
Weekday: i.Weekday,
73+
DayOfMonth: i.DayOfMonth,
74+
}
75+
}
76+
6777
// daily trigger: honour the TimeOfDay slot and catch up the previous one
6878
func (i *Interval) shouldTriggerDaily(now, lastBackup time.Time) bool {
6979
if i.TimeOfDay == nil {

0 commit comments

Comments
 (0)