Skip to content

Commit

Permalink
fix: show bacalhau id error (#192)
Browse files Browse the repository at this point in the history
* fix: show bacalhau id error

* fix: ignore bacalhau cli error

* fix: log output errors from bacalhau id

---------

Co-authored-by: James Walker <walkah@walkah.net>
  • Loading branch information
hunjixin and walkah authored Jun 27, 2024
1 parent 76b8fd8 commit d776217
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 12 additions & 4 deletions pkg/executor/bacalhau/bacalhau.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,26 @@ func (executor *BacalhauExecutor) Id() (string, error) {
)
nodeIdCmd.Env = executor.bacalhauEnv

output, err := nodeIdCmd.CombinedOutput()
runOutputRaw, err := nodeIdCmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("error calling get id results %s", err.Error())
return "", fmt.Errorf("error calling get id results %s, %s", err.Error(), runOutputRaw)
}

splitOutputs := strings.Split(string(runOutputRaw), "\n")
runOutput := splitOutputs[len(splitOutputs)-1]
outputError := strings.Join(strings.Fields(strings.Join(splitOutputs[:len(splitOutputs)-1], " ")), " ")
if outputError != "" {
// TODO: we need to figure out if errors here are fatal or not
log.Warn().Msgf("error calling bacalhau id: %s", outputError)
}

var idResult struct {
ID string
ClientID string
}
err = json.Unmarshal(output, &idResult)
err = json.Unmarshal([]byte(runOutput), &idResult)
if err != nil {
return "", fmt.Errorf("error unmarshalling job JSON %s", err.Error())
return "", fmt.Errorf("error unmarshalling job JSON %s %s", err.Error(), runOutputRaw)
}

return idResult.ID, nil
Expand Down
10 changes: 7 additions & 3 deletions pkg/resourceprovider/resourceprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,20 @@ func NewResourceProvider(

func (resourceProvider *ResourceProvider) Start(ctx context.Context, cm *system.CleanupManager) chan error {
if !resourceProvider.options.Pow.DisablePow {
go resourceProvider.StartMineLoop(ctx)
if errCh := resourceProvider.StartMineLoop(ctx); errCh != nil {
return errCh
}
}
return resourceProvider.controller.Start(ctx, cm)
}

func (resourceProvider *ResourceProvider) StartMineLoop(ctx context.Context) error {
func (resourceProvider *ResourceProvider) StartMineLoop(ctx context.Context) chan error {
errorChan := make(chan error, 1)
walletAddress := resourceProvider.web3SDK.GetAddress()
nodeId, err := resourceProvider.controller.executor.Id()
if err != nil {
return err
errorChan <- err
return errorChan
}
log.Info().Msgf("Wallet %s node id %s is ready for mine", walletAddress, nodeId)

Expand Down

0 comments on commit d776217

Please sign in to comment.