include latest and earliest record times in state
Generate check / check-changes (pull_request) Successful in 2s
Generate check / verify-generate (pull_request) Skipped
Quality / check-changes (pull_request) Successful in 2s
Quality / static-checks (pull_request) Successful in 56s
Quality / run-tests (pull_request) Failing after 55s

This commit is contained in:
natercio committed 2026-10-12 22:58:09 +01:00
1 parent 47f38fce2b
commit 79151422b0
2 files changed
+22 -6

No files matched your search

+19 -6
View File
@@ -96,11 +96,9 @@ func (fs *JSONStore) Load(ctx context.Context) (map[string]*FillerQueue, error)
// the same directory followed by an atomic rename so a crash mid-write cannot // the same directory followed by an atomic rename so a crash mid-write cannot
// leave a half-written state file. // leave a half-written state file.
func (fs *JSONStore) Save(ctx context.Context, queue map[string]*FillerQueue) error { func (fs *JSONStore) Save(ctx context.Context, queue map[string]*FillerQueue) error {
state := State{ queues := make(map[string][]persistedFiller)
Version: StateVersion, latest := time.Time{}
Platform: fs.platform, earliest := time.Time{}
Queues: make(map[string][]persistedFiller),
}
for symbol, q := range queue { for symbol, q := range queue {
if q == nil || q.Len() == 0 { if q == nil || q.Len() == 0 {
@@ -119,8 +117,23 @@ func (fs *JSONStore) Save(ctx context.Context, queue map[string]*FillerQueue) er
Price: f.Price(), Price: f.Price(),
Filled: f.Filled(), Filled: f.Filled(),
}) })
if f.Timestamp().After(latest) {
latest = f.Timestamp()
} }
state.Queues[symbol] = persisted if f.Timestamp().Before(earliest) || earliest.IsZero() {
earliest = f.Timestamp()
}
}
queues[symbol] = persisted
}
state := State{
Version: StateVersion,
Platform: fs.platform,
Queues: queues,
Latest: latest,
Earliest: earliest,
} }
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
+3
View File
@@ -3,6 +3,7 @@ package internal
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"time"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
) )
@@ -15,6 +16,8 @@ const StateVersion = "2"
type State struct { type State struct {
Version string `json:"version"` Version string `json:"version"`
Platform string `json:"platform"` Platform string `json:"platform"`
Latest time.Time `json:"latest"`
Earliest time.Time `json:"earliest"`
Queues map[string][]persistedFiller `json:"queues"` Queues map[string][]persistedFiller `json:"queues"`
} }