Skip to content

Commit

Permalink
save the failed store links but still update time
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Mar 23, 2024
1 parent c846d73 commit 51e92b2
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion blox/blox.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,36 @@ func (p *Blox) UpdateLastCheckedTime() error {
return nil
}

// UpdateFailedCids updates the last checked time by appending failed CIDs to a file.
// It collects all errors encountered and returns them together.
func (p *Blox) UpdateFailedCids(links []datamodel.Link) error {
lastFailedFile := "/uniondrive/failed_cids.info"
// Open the file in append mode. If it doesn't exist, create it.
file, err := os.OpenFile(lastFailedFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer file.Close()

var errorMessages []string

for _, link := range links {
_, err := file.WriteString(link.String() + "\n")
if err != nil {
// Collect the error message.
errorMessages = append(errorMessages, err.Error())
continue
}
}

if len(errorMessages) > 0 {
// Join all error messages into a single string and return it as an error.
return fmt.Errorf("errors occurred while updating failed CIDs: %s", strings.Join(errorMessages, "; "))
}

return nil
}

func (p *Blox) Start(ctx context.Context) error {
ctx = network.WithUseTransient(ctx, "fx.exchange")
// implemented topic validators with chain integration.
Expand Down Expand Up @@ -701,7 +731,8 @@ func (p *Blox) Start(ctx context.Context) error {
} else {
// For any other error, log and continue
log.Errorw("Error calling HandleManifestBatchStore", "err", err, "p.topicName", p.topicName, "storedLinks", storedLinks)
continue
p.UpdateFailedCids(storedLinks)
//continue
}
}
}
Expand Down

0 comments on commit 51e92b2

Please sign in to comment.