Skip to content

Commit

Permalink
fix: Handle accept result and download result errors (#416)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
bgins authored Oct 31, 2024
1 parent d0b40cc commit c2c4a11
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions pkg/jobcreator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package jobcreator

import (
"context"
"errors"
"fmt"
"io/fs"
"os"
"time"

"github.com/lilypad-tech/lilypad/pkg/data"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}
}

Expand All @@ -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) {
Expand Down

0 comments on commit c2c4a11

Please sign in to comment.