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,8 +12,8 @@ import (
"sync"
"time"
"github.com/robfig/cron/v3"
"chorus/pkg/crypto"
"github.com/robfig/cron/v3"
)
// BackupManagerImpl implements the BackupManager interface
@@ -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
@@ -163,7 +163,7 @@ func (bm *BackupManagerImpl) CreateBackup(
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(),

View File

@@ -3,9 +3,9 @@ package storage
import (
"time"
"chorus/pkg/ucxl"
"chorus/pkg/crypto"
slurpContext "chorus/pkg/slurp/context"
"chorus/pkg/ucxl"
)
// ListCriteria represents criteria for listing contexts
@@ -315,12 +315,15 @@ type BackupInfo struct {
type BackupStatus string
const (
BackupInProgress BackupStatus = "in_progress"
BackupCompleted BackupStatus = "completed"
BackupFailed BackupStatus = "failed"
BackupCorrupted BackupStatus = "corrupted"
BackupStatusInProgress BackupStatus = "in_progress"
BackupStatusCompleted BackupStatus = "completed"
BackupStatusFailed BackupStatus = "failed"
BackupStatusCorrupted BackupStatus = "corrupted"
)
// DistributedStorageOptions aliases DistributedStoreOptions for backwards compatibility.
type DistributedStorageOptions = DistributedStoreOptions
// RestoreConfig represents restore configuration
type RestoreConfig struct {
BackupID string `json:"backup_id"` // Backup to restore from