Disambiguate backup status constants for SLURP storage

This commit is contained in:
anthonyrawlins
2025-09-27 15:47:18 +10:00
parent a99469f346
commit acc4361463
2 changed files with 274 additions and 271 deletions

View File

@@ -12,35 +12,35 @@ import (
"sync"
"time"
"github.com/robfig/cron/v3"
"chorus/pkg/crypto"
"github.com/robfig/cron/v3"
)
// BackupManagerImpl implements the BackupManager interface
type BackupManagerImpl struct {
mu sync.RWMutex
contextStore *ContextStoreImpl
crypto crypto.RoleCrypto
basePath string
nodeID string
schedules map[string]*cron.Cron
backups map[string]*BackupInfo
runningBackups map[string]*BackupJob
options *BackupManagerOptions
notifications chan *BackupEvent
stopCh chan struct{}
mu sync.RWMutex
contextStore *ContextStoreImpl
crypto crypto.RoleCrypto
basePath string
nodeID string
schedules map[string]*cron.Cron
backups map[string]*BackupInfo
runningBackups map[string]*BackupJob
options *BackupManagerOptions
notifications chan *BackupEvent
stopCh chan struct{}
}
// BackupManagerOptions configures backup manager behavior
type BackupManagerOptions struct {
MaxConcurrentBackups int `json:"max_concurrent_backups"`
CompressionEnabled bool `json:"compression_enabled"`
EncryptionEnabled bool `json:"encryption_enabled"`
RetentionDays int `json:"retention_days"`
ValidationEnabled bool `json:"validation_enabled"`
NotificationsEnabled bool `json:"notifications_enabled"`
BackupTimeout time.Duration `json:"backup_timeout"`
CleanupInterval time.Duration `json:"cleanup_interval"`
MaxConcurrentBackups int `json:"max_concurrent_backups"`
CompressionEnabled bool `json:"compression_enabled"`
EncryptionEnabled bool `json:"encryption_enabled"`
RetentionDays int `json:"retention_days"`
ValidationEnabled bool `json:"validation_enabled"`
NotificationsEnabled bool `json:"notifications_enabled"`
BackupTimeout time.Duration `json:"backup_timeout"`
CleanupInterval time.Duration `json:"cleanup_interval"`
}
// BackupJob represents a running backup operation
@@ -69,14 +69,14 @@ type BackupEvent struct {
type BackupEventType string
const (
BackupStarted BackupEventType = "backup_started"
BackupProgress BackupEventType = "backup_progress"
BackupCompleted BackupEventType = "backup_completed"
BackupFailed BackupEventType = "backup_failed"
BackupValidated BackupEventType = "backup_validated"
BackupRestored BackupEventType = "backup_restored"
BackupDeleted BackupEventType = "backup_deleted"
BackupScheduled BackupEventType = "backup_scheduled"
BackupEventStarted BackupEventType = "backup_started"
BackupEventProgress BackupEventType = "backup_progress"
BackupEventCompleted BackupEventType = "backup_completed"
BackupEventFailed BackupEventType = "backup_failed"
BackupEventValidated BackupEventType = "backup_validated"
BackupEventRestored BackupEventType = "backup_restored"
BackupEventDeleted BackupEventType = "backup_deleted"
BackupEventScheduled BackupEventType = "backup_scheduled"
)
// DefaultBackupManagerOptions returns sensible defaults
@@ -112,15 +112,15 @@ func NewBackupManager(
bm := &BackupManagerImpl{
contextStore: contextStore,
crypto: crypto,
basePath: basePath,
nodeID: nodeID,
schedules: make(map[string]*cron.Cron),
backups: make(map[string]*BackupInfo),
crypto: crypto,
basePath: basePath,
nodeID: nodeID,
schedules: make(map[string]*cron.Cron),
backups: make(map[string]*BackupInfo),
runningBackups: make(map[string]*BackupJob),
options: options,
notifications: make(chan *BackupEvent, 100),
stopCh: make(chan struct{}),
options: options,
notifications: make(chan *BackupEvent, 100),
stopCh: make(chan struct{}),
}
// Load existing backup metadata
@@ -154,16 +154,16 @@ func (bm *BackupManagerImpl) CreateBackup(
// Create backup info
backupInfo := &BackupInfo{
ID: backupID,
BackupID: backupID,
Name: config.Name,
Destination: config.Destination,
ID: backupID,
BackupID: backupID,
Name: config.Name,
Destination: config.Destination,
IncludesIndexes: config.IncludeIndexes,
IncludesCache: config.IncludeCache,
Encrypted: config.Encryption,
Incremental: config.Incremental,
ParentBackupID: config.ParentBackupID,
Status: BackupInProgress,
Status: BackupStatusInProgress,
CreatedAt: time.Now(),
RetentionUntil: time.Now().Add(config.Retention),
}
@@ -174,7 +174,7 @@ func (bm *BackupManagerImpl) CreateBackup(
ID: backupID,
Config: config,
StartTime: time.Now(),
Status: BackupInProgress,
Status: BackupStatusInProgress,
cancel: cancel,
}
@@ -186,7 +186,7 @@ func (bm *BackupManagerImpl) CreateBackup(
// Notify backup started
bm.notify(&BackupEvent{
Type: BackupStarted,
Type: BackupEventStarted,
BackupID: backupID,
Message: fmt.Sprintf("Backup '%s' started", config.Name),
Timestamp: time.Now(),
@@ -213,7 +213,7 @@ func (bm *BackupManagerImpl) RestoreBackup(
return fmt.Errorf("backup %s not found", backupID)
}
if backupInfo.Status != BackupCompleted {
if backupInfo.Status != BackupStatusCompleted {
return fmt.Errorf("backup %s is not completed (status: %s)", backupID, backupInfo.Status)
}
@@ -276,7 +276,7 @@ func (bm *BackupManagerImpl) DeleteBackup(ctx context.Context, backupID string)
// Notify deletion
bm.notify(&BackupEvent{
Type: BackupDeleted,
Type: BackupEventDeleted,
BackupID: backupID,
Message: fmt.Sprintf("Backup '%s' deleted", backupInfo.Name),
Timestamp: time.Now(),
@@ -348,7 +348,7 @@ func (bm *BackupManagerImpl) ValidateBackup(
// Notify validation completed
bm.notify(&BackupEvent{
Type: BackupValidated,
Type: BackupEventValidated,
BackupID: backupID,
Message: fmt.Sprintf("Backup validation completed (valid: %v)", validation.Valid),
Timestamp: time.Now(),
@@ -396,7 +396,7 @@ func (bm *BackupManagerImpl) ScheduleBackup(
// Notify scheduling
bm.notify(&BackupEvent{
Type: BackupScheduled,
Type: BackupEventScheduled,
BackupID: schedule.ID,
Message: fmt.Sprintf("Backup schedule '%s' created", schedule.Name),
Timestamp: time.Now(),
@@ -429,13 +429,13 @@ func (bm *BackupManagerImpl) GetBackupStats(ctx context.Context) (*BackupStatist
for _, backup := range bm.backups {
switch backup.Status {
case BackupCompleted:
case BackupStatusCompleted:
stats.SuccessfulBackups++
if backup.CompletedAt != nil {
backupTime := backup.CompletedAt.Sub(backup.CreatedAt)
totalTime += backupTime
}
case BackupFailed:
case BackupStatusFailed:
stats.FailedBackups++
}
@@ -544,7 +544,7 @@ func (bm *BackupManagerImpl) performBackup(
// Update backup info
completedAt := time.Now()
bm.mu.Lock()
backupInfo.Status = BackupCompleted
backupInfo.Status = BackupStatusCompleted
backupInfo.DataSize = finalSize
backupInfo.CompressedSize = finalSize // Would be different if compression is applied
backupInfo.Checksum = checksum
@@ -560,7 +560,7 @@ func (bm *BackupManagerImpl) performBackup(
// Notify completion
bm.notify(&BackupEvent{
Type: BackupCompleted,
Type: BackupEventCompleted,
BackupID: job.ID,
Message: fmt.Sprintf("Backup '%s' completed successfully", job.Config.Name),
Timestamp: time.Now(),
@@ -607,7 +607,7 @@ func (bm *BackupManagerImpl) performRestore(
// Notify restore completion
bm.notify(&BackupEvent{
Type: BackupRestored,
Type: BackupEventRestored,
BackupID: backupInfo.BackupID,
Message: fmt.Sprintf("Backup '%s' restored successfully", backupInfo.Name),
Timestamp: time.Now(),
@@ -706,13 +706,13 @@ func (bm *BackupManagerImpl) validateFile(filePath string) error {
func (bm *BackupManagerImpl) failBackup(job *BackupJob, backupInfo *BackupInfo, err error) {
bm.mu.Lock()
backupInfo.Status = BackupFailed
backupInfo.Status = BackupStatusFailed
backupInfo.ErrorMessage = err.Error()
job.Error = err
bm.mu.Unlock()
bm.notify(&BackupEvent{
Type: BackupFailed,
Type: BackupEventFailed,
BackupID: job.ID,
Message: fmt.Sprintf("Backup '%s' failed: %v", job.Config.Name, err),
Timestamp: time.Now(),