From d79f80b073f8ea820239dfc5041ec244cbc4baff Mon Sep 17 00:00:00 2001 From: amecea Date: Fri, 7 Dec 2018 16:53:28 +0200 Subject: [PATCH] Wait with channels for comamnds to finish --- .../mysqlbackup/internal/syncer/job_test.go | 2 +- pkg/sidecar/apptakebackup/apptakebackup.go | 24 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pkg/controller/mysqlbackup/internal/syncer/job_test.go b/pkg/controller/mysqlbackup/internal/syncer/job_test.go index 5e562b9c8..79560d0f1 100644 --- a/pkg/controller/mysqlbackup/internal/syncer/job_test.go +++ b/pkg/controller/mysqlbackup/internal/syncer/job_test.go @@ -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))) }) diff --git a/pkg/sidecar/apptakebackup/apptakebackup.go b/pkg/sidecar/apptakebackup/apptakebackup.go index 2aafb92f0..d71820f65 100644 --- a/pkg/sidecar/apptakebackup/apptakebackup.go +++ b/pkg/sidecar/apptakebackup/apptakebackup.go @@ -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