implemented persistence
Generate check / check-changes (pull_request) Successful in 36s
Quality / check-changes (pull_request) Successful in 35s
Generate check / verify-generate (pull_request) Successful in 48s
Quality / run-tests (pull_request) Successful in 51s

This commit is contained in:
2026-08-02 15:53:27 +01:00
parent 6fcc21adfe
commit 5fe47746fa
15 changed files with 1447 additions and 48 deletions
+4 -10
View File
@@ -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 {