Include latest and earliest record times in state #34
No files matched your search
+19
-6
@@ -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,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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user