implemented persistence
This commit is contained in:
+4
-10
@@ -75,8 +75,8 @@ func WithSelector(s Selector) Option {
|
||||
}
|
||||
|
||||
type Store interface {
|
||||
Load() (map[string]*FillerQueue, error)
|
||||
Save(map[string]*FillerQueue) error
|
||||
Load(context.Context) (map[string]*FillerQueue, error)
|
||||
Save(context.Context, map[string]*FillerQueue) error
|
||||
}
|
||||
|
||||
func WithStore(s Store) Option {
|
||||
@@ -93,7 +93,7 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
|
||||
store: EphemeralStore{},
|
||||
}, options)
|
||||
|
||||
buys, err := optionals.store.Load()
|
||||
buys, err := optionals.store.Load(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("loading state: %w", err)
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
|
||||
rec, err := reader.ReadRecord(ctx)
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
err = optionals.store.Save(buys)
|
||||
err = optionals.store.Save(ctx, buys)
|
||||
if err != nil {
|
||||
return fmt.Errorf("saving state: %w", err)
|
||||
}
|
||||
@@ -182,12 +182,6 @@ func processRecord(ctx context.Context, q *FillerQueue, rec Record, sel Selector
|
||||
return ErrInsufficientBoughtVolume
|
||||
}
|
||||
|
||||
// Since we don't apply selectors while processing buys we need to apply them here, before we
|
||||
// actually use them.
|
||||
if !sel(buy) {
|
||||
continue
|
||||
}
|
||||
|
||||
matchedQty, filled := buy.Fill(unmatchedQty)
|
||||
|
||||
if filled {
|
||||
|
||||
Reference in New Issue
Block a user