-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove old device_connections
in worker, remove connection state stored on device
#1807
Conversation
87be70f
to
ab30c3d
Compare
|> join(:inner, [dc], d in Device, on: dc.device_id == d.id) | ||
|> where([dc, _d], dc.last_seen_at < ^days_ago) | ||
|> where([dc, _d], dc.status != :connected) | ||
|> where([dc, d], dc.id != d.latest_connection_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is sooooo smart!!!!!
lib/nerves_hub/devices/device.ex
Outdated
@@ -44,6 +40,7 @@ defmodule NervesHub.Devices.Device do | |||
embeds_one(:firmware_metadata, FirmwareMetadata, on_replace: :update) | |||
has_many(:device_certificates, DeviceCertificate, on_delete: :delete_all) | |||
has_many(:device_connections, DeviceConnection, on_delete: :delete_all) | |||
has_one(:latest_connection, DeviceConnection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌
worker, introduce device.latest_connection, remove unused connection references on devices
ab30c3d
to
e666f7f
Compare
@@ -1,6 +1,7 @@ | |||
defmodule NervesHub.Workers.ScheduleOrgAuditLogTruncation do | |||
use Oban.Worker, | |||
queue: :truncation | |||
queue: :truncation, | |||
max_attempts: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this from config.exs
.
device_connections
in worker, remove connection state stored on device
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment, but lets test this out!
6c8f522
to
bd8e1c6
Compare
device.latest_connection
, which references the latestdevice_connection
record for the devicedevice_connections
every hour withNervesHub.Workers.DeleteOldDeviceConnections
last_seen_at
older than two weeks by default (configurable), astatus
of:disconnected
and does not delete a device's lastdevice_connection
, even if the previous criteria are metconnection_status
,connection_established_at
, andconnection_last_seen_at
from thedevice
schema.device.latest_connection
, simplifying a lot of queries and logic related todevice_connections
Devices.clean_connection_states
and it's call from a worker sincedevice.connection_status
was removed and connection logic is moving todevice.latest_connection
device_connection
asdevice.lastest_connection
device.latest_connection
when seeding devicesTodo: