Internal state persistence #27
+8
-12
@@ -98,10 +98,11 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
|
|||||||
return fmt.Errorf("loading state: %w", err)
|
return fmt.Errorf("loading state: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var buysCount, sellsCount int64
|
var (
|
||||||
var lastTimestamp time.Time
|
recordsCount int64
|
||||||
progTicker := time.NewTicker(10 * time.Second)
|
lastTimestamp time.Time
|
||||||
|
progTicker = time.NewTicker(10 * time.Second)
|
||||||
|
)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@@ -109,9 +110,7 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
|
|||||||
case <-progTicker.C:
|
case <-progTicker.C:
|
||||||
slog.InfoContext(
|
slog.InfoContext(
|
||||||
ctx, "Progress update",
|
ctx, "Progress update",
|
||||||
slog.Int64("total_records", buysCount+sellsCount),
|
slog.Int64("records_count", recordsCount),
|
||||||
slog.Int64("sell_records", sellsCount),
|
|
||||||
slog.Int64("buy_records", buysCount),
|
|
||||||
slog.Time("last_record_timestamp", lastTimestamp),
|
slog.Time("last_record_timestamp", lastTimestamp),
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
@@ -128,15 +127,12 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if rec.Kind().Is(KindBuy) {
|
if !rec.Kind().Valid() {
|
||||||
buysCount++
|
|
||||||
} else if rec.Kind().Is(KindSell) {
|
|
||||||
sellsCount++
|
|
||||||
} else if !rec.Kind().Valid() {
|
|
||||||
return fmt.Errorf("cannot process Kind(%d)", rec.Kind())
|
return fmt.Errorf("cannot process Kind(%d)", rec.Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTimestamp = rec.Timestamp()
|
lastTimestamp = rec.Timestamp()
|
||||||
|
recordsCount++
|
||||||
|
|
||||||
buyQueue, ok := buys[rec.Symbol()]
|
buyQueue, ok := buys[rec.Symbol()]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user