make use of the store optional

This commit is contained in:
2026-07-11 16:43:27 +01:00
parent b70ac40e37
commit 4fc5cd22ea
+11 -2
View File
@@ -93,7 +93,10 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
store: EphemeralStore{}, store: EphemeralStore{},
}, options) }, options)
buys := make(map[string]*FillerQueue) buys, err := optionals.store.Load()
if err != nil {
return fmt.Errorf("loading state: %w", err)
}
var buysCount, sellsCount int64 var buysCount, sellsCount int64
var lastTimestamp time.Time var lastTimestamp time.Time
@@ -115,6 +118,11 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
rec, err := reader.ReadRecord(ctx) rec, err := reader.ReadRecord(ctx)
if err != nil { if err != nil {
if errors.Is(err, io.EOF) { if errors.Is(err, io.EOF) {
err = optionals.store.Save(buys)
if err != nil {
return fmt.Errorf("saving state: %w", err)
}
return nil return nil
} }
return err return err
@@ -138,9 +146,10 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
if err != nil { if err != nil {
return fmt.Errorf("processing record: %w", err) return fmt.Errorf("processing record: %w", err)
} }
} }
} }
return nil
} }
// processRecord either adds buys to the queue or consumes buys from the queue when processing a // processRecord either adds buys to the queue or consumes buys from the queue when processing a