Skip to content

Commit

Permalink
Wait with channels for comamnds to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
AMecea committed Dec 7, 2018
1 parent 2785826 commit d79f80b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/mysqlbackup/internal/syncer/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var _ = Describe("MysqlBackup job syncer", func() {
}
})

It("should return the master if nothing is status", func() {
It("should return the master if status is empty/unknown", func() {
Expect(syncer.getBackupCandidate()).To(Equal(cluster.GetPodHostname(0)))
})

Expand Down
24 changes: 11 additions & 13 deletions pkg/sidecar/apptakebackup/apptakebackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,20 @@ func pushBackupFromTo(srcHost, destBucket string) error {
return err
}

if err := gzip.Start(); err != nil {
return fmt.Errorf("gzip start error: %s", err)
}
errChan := make(chan error, 2)

if err := rclone.Start(); err != nil {
return fmt.Errorf("rclone start error: %s", err)
}
go func() {
log.V(2).Info("wait for gzip to finish")
errChan <- gzip.Run()
}()

log.V(2).Info("wait for rclone to finish")
if err := rclone.Wait(); err != nil {
return fmt.Errorf("rclone wait error: %s", err)
}
go func() {
log.V(2).Info("wait for rclone to finish")
errChan <- rclone.Run()
}()

log.V(2).Info("wait for gzip to finish")
if err := gzip.Wait(); err != nil {
return fmt.Errorf("gzip wait error: %s", err)
if err := <-errChan; err != nil {
return err
}

return nil
Expand Down

0 comments on commit d79f80b

Please sign in to comment.