Skip to content

Commit

Permalink
fix background backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Son Roy Almerol committed Nov 14, 2024
1 parent 84b876f commit 8a36685
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cmd/pbs_plus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion internal/backend/backup/jobrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/proxy/controllers/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a36685

Please sign in to comment.