Skip to content

Commit 042574f

Browse files
committed
fix(dup): last_connection / last_disconnection timestamp unit
timestamps were in millisecond precision, but `DateTime.from_unix!` was given microsecond precision. This caused datetimes to be incorrect. this was the result after setting up astarte in 5 minutes and running astarte-stream-qt5-test ``` ❯ docker compose exec -it scylla cqlsh -e 'select last_connection from test.devices;' last_connection --------------------------------- 1970-01-21 03:48:22.216000+0000 ``` Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
1 parent 1ed24d1 commit 042574f

File tree

2 files changed

+4
-2
lines changed
  • apps/astarte_data_updater_plant/lib/astarte_data_updater_plant/data_updater

2 files changed

+4
-2
lines changed

apps/astarte_data_updater_plant/lib/astarte_data_updater_plant/data_updater/impl.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Impl do
130130
Queries.set_device_connected!(
131131
new_state.realm,
132132
new_state.device_id,
133-
DateTime.from_unix!(timestamp_ms, :microsecond),
133+
DateTime.from_unix!(timestamp_ms, :millisecond),
134134
ip_address
135135
)
136136

@@ -2244,7 +2244,7 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Impl do
22442244
Queries.set_device_disconnected!(
22452245
state.realm,
22462246
state.device_id,
2247-
DateTime.from_unix!(timestamp_ms, :microsecond),
2247+
DateTime.from_unix!(timestamp_ms, :millisecond),
22482248
state.total_received_msgs,
22492249
state.total_received_bytes,
22502250
state.interface_exchanged_msgs,

apps/astarte_data_updater_plant/lib/astarte_data_updater_plant/data_updater/queries.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Queries do
457457

458458
defp set_connection_info!(realm, device_id, timestamp, ip_address) do
459459
keyspace_name = Realm.keyspace_name(realm)
460+
timestamp = Ecto.Type.cast!(:utc_datetime_usec, timestamp)
460461

461462
%Device{device_id: device_id}
462463
|> Ecto.Changeset.change(
@@ -515,6 +516,7 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Queries do
515516
interface_exchanged_bytes
516517
) do
517518
keyspace_name = Realm.keyspace_name(realm)
519+
timestamp_ms = Ecto.Type.cast!(:utc_datetime_usec, timestamp_ms)
518520

519521
%Device{device_id: device_id}
520522
|> Ecto.Changeset.change(

0 commit comments

Comments
 (0)