Skip to content

Commit

Permalink
move file mutex to main backup function
Browse files Browse the repository at this point in the history
  • Loading branch information
sonroyaalmerol committed Jan 11, 2025
1 parent a984ac2 commit 78749ec
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions internal/backend/backup/jobrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ type openResult struct {
}

func RunBackup(job *store.Job, storeInstance *store.Store) (*store.Task, error) {
backupMutex, err := filemutex.New("/tmp/pbs-plus-mutex-lock")
if err != nil {
return nil, fmt.Errorf("RunBackup: failed to create mutex lock: %w", err)
}
defer backupMutex.Close() // Ensure mutex is always closed

if err := backupMutex.Lock(); err != nil {
return nil, fmt.Errorf("RunBackup: failed to acquire lock: %w", err)
}
defer backupMutex.Unlock()

// Create a context with timeout for the entire operation
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -363,17 +374,6 @@ func mountAgent(ctx context.Context, storeInstance *store.Store, target *store.T
}

func monitorTask(ctx context.Context, storeInstance *store.Store, job *store.Job, taskChan chan store.Task) (*store.Task, error) {
backupMutex, err := filemutex.New("/tmp/pbs-plus-mutex-lock")
if err != nil {
return nil, fmt.Errorf("RunBackup: failed to create mutex lock: %w", err)
}
defer backupMutex.Close() // Ensure mutex is always closed

if err := backupMutex.Lock(); err != nil {
return nil, fmt.Errorf("RunBackup: failed to acquire lock: %w", err)
}
defer backupMutex.Unlock()

errChan := make(chan error, 1)
resultChan := make(chan *store.Task, 1)

Expand Down

0 comments on commit 78749ec

Please sign in to comment.