fix(telemetry): ts = время приёма (ReceivedAt), а не момент INSERT
Раньше ts проставлялся now() в БД при INSERT → при батчинге и параллельных записях порядок телеметрии (ORDER BY ts DESC) ломался. Теперь в ts идёт ReceivedAt из envelope (серверное время приёма, ставит bridge); битый/пустой received_at → zero → стор подставляет now(). Схема не меняется (используется существующая колонка ts). Обновлены callers: consumer/processor.go и legacy cmd/sqs-consumer.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"gitea.services.ngcloud.ru/Nail/IoT/internal/service/bridge"
|
||||
"gitea.services.ngcloud.ru/Nail/IoT/internal/storage/iotpg"
|
||||
@@ -29,7 +30,13 @@ func processTelemetry(ctx context.Context, body string, store *iotpg.IoTPostgres
|
||||
if err := store.EnsureTenantDB(ctx, envelope.Namespace); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := store.InsertTelemetry(ctx, envelope.Namespace, envelope.DeviceID, envelope.MessageID, envelope.Payload); err != nil {
|
||||
// Время приёма сохраняем в ts (порядок телеметрии). Битый/пустой received_at
|
||||
// → zero, стор подставит now().
|
||||
receivedAt, perr := time.Parse(time.RFC3339, envelope.ReceivedAt)
|
||||
if perr != nil {
|
||||
receivedAt = time.Time{}
|
||||
}
|
||||
if err := store.InsertTelemetry(ctx, envelope.Namespace, envelope.DeviceID, envelope.MessageID, receivedAt, envelope.Payload); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user