Skip to content

Commit

Permalink
use goroutine for taskChan receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
sonroyaalmerol committed Nov 18, 2024
1 parent 7c2e9f4 commit d8d4431
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/backend/backup/jobrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func RunBackup(job *store.Job, storeInstance *store.Store, waitChan chan struct{
return nil, fmt.Errorf("RunBackup: proxmox-backup-client start error (%s) -> %w", cmd.String(), err)
}

var task *store.Task
go func() {
taskC := <-taskChan
task = &taskC
}()

for {
line, err := logBuffer.ReadString('\n')
if err != nil && line != "" {
Expand All @@ -146,8 +152,9 @@ func RunBackup(job *store.Job, storeInstance *store.Store, waitChan chan struct{
time.Sleep(time.Millisecond * 100)
}

task, ok := <-taskChan
if !ok {
<-watchCtx.Done()

if task == nil {
return nil, fmt.Errorf("RunBackup: task not found -> %w", err)
}

Expand Down
1 change: 1 addition & 0 deletions internal/store/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (storeInstance *Store) GetMostRecentTask(ctx context.Context, job *Job) (ch
return
}
returnChan <- *newTask
return
}
}
}
Expand Down

0 comments on commit d8d4431

Please sign in to comment.