From c2c4a116a273ac9bfc26a7189f8d104492d24a26 Mon Sep 17 00:00:00 2001 From: Brian Ginsburg <7957636+bgins@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:35:39 -0700 Subject: [PATCH] fix: Handle accept result and download result errors (#416) * fix: Add accept result error handling * fix: Add download result error handling * fix: Check download path before downloading If the path exists, we have already attempted to download the results. * fix: Unblock error channel The unbuffered error channel blocks on the receiver which does not get set up in time. The buffered channel will hold the message until the receiver is available. --- pkg/jobcreator/controller.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/pkg/jobcreator/controller.go b/pkg/jobcreator/controller.go index 8cb3e846..a8fc8ed3 100644 --- a/pkg/jobcreator/controller.go +++ b/pkg/jobcreator/controller.go @@ -2,7 +2,10 @@ package jobcreator import ( "context" + "errors" "fmt" + "io/fs" + "os" "time" "github.com/lilypad-tech/lilypad/pkg/data" @@ -161,7 +164,7 @@ func (controller *JobCreatorController) subscribeToWeb3() error { } func (controller *JobCreatorController) Start(ctx context.Context, cm *system.CleanupManager) chan error { - errorChan := make(chan error) + errorChan := make(chan error, 1) err := controller.subscribeToSolver() if err != nil { errorChan <- err @@ -319,9 +322,23 @@ func (controller *JobCreatorController) checkResults() error { // there is an error with the job // accept anyway // TODO: trigger mediation here - controller.acceptResult(dealContainer) + err := controller.acceptResult(dealContainer) + if err != nil { + controller.log.Error("failed to accept results", err) + return err + } } else { - controller.downloadResult(dealContainer) + // We check for all completed deals, including deals whose results + // we have already downloaded. Check the download path and download + // if results do not exist. + downloadPath := solver.GetDownloadsFilePath(dealContainer.ID) + if _, err := os.Stat(downloadPath); errors.Is(err, fs.ErrNotExist) { + err := controller.downloadResult(dealContainer) + if err != nil { + controller.log.Error("failed to download results", err) + return err + } + } } } @@ -337,7 +354,11 @@ func (controller *JobCreatorController) downloadResult(dealContainer data.DealCo controller.log.Debug("Downloaded results for job", solver.GetDownloadsFilePath(dealContainer.ID)) // TODO: activate the mediation check here - controller.acceptResult(dealContainer) + err = controller.acceptResult(dealContainer) + if err != nil { + controller.log.Error("failed to accept results", err) + return err + } // work out if we should check or accept the results // if controller.options.Mediation.CheckResultsPercentage >= rand.Intn(100) {