diff --git a/cmd/pbs_plus/main.go b/cmd/pbs_plus/main.go index 5c17c1f..aa1aaaa 100644 --- a/cmd/pbs_plus/main.go +++ b/cmd/pbs_plus/main.go @@ -110,9 +110,13 @@ func main() { return } - _, err = backup.RunBackup(jobTask, storeInstance) + waitChan := make(chan struct{}) + _, err = backup.RunBackup(jobTask, storeInstance, waitChan) if err != nil { + close(waitChan) s.Error(err) + } else { + <-waitChan } return diff --git a/internal/backend/backup/jobrun.go b/internal/backend/backup/jobrun.go index 9a6c4d2..d472aa6 100644 --- a/internal/backend/backup/jobrun.go +++ b/internal/backend/backup/jobrun.go @@ -17,7 +17,7 @@ import ( "github.com/sonroyaalmerol/pbs-plus/internal/syslog" ) -func RunBackup(job *store.Job, storeInstance *store.Store) (*store.Task, error) { +func RunBackup(job *store.Job, storeInstance *store.Store, waitChan chan struct{}) (*store.Task, error) { if storeInstance.APIToken == nil { return nil, fmt.Errorf("RunBackup: api token is required") } @@ -161,6 +161,11 @@ func RunBackup(job *store.Job, storeInstance *store.Store) (*store.Task, error) } go func() { + defer func() { + if waitChan != nil { + close(waitChan) + } + }() syslogger, err := syslog.InitializeLogger() if err != nil { log.Printf("Failed to initialize logger: %s", err) diff --git a/internal/proxy/controllers/jobs/jobs.go b/internal/proxy/controllers/jobs/jobs.go index d1e4275..6f93e43 100644 --- a/internal/proxy/controllers/jobs/jobs.go +++ b/internal/proxy/controllers/jobs/jobs.go @@ -58,7 +58,7 @@ func ExtJsJobRunHandler(storeInstance *store.Store) func(http.ResponseWriter, *h return } - task, err := backup.RunBackup(job, storeInstance) + task, err := backup.RunBackup(job, storeInstance, nil) if err != nil { controllers.WriteErrorResponse(w, err) return