Skip to content

Commit

Permalink
Add last_api_heartbeat_state_change_event to the device model
Browse files Browse the repository at this point in the history
Resolves: #644
Change-type: minor
  • Loading branch information
thgreasi committed May 9, 2023
1 parent 0b3fd60 commit 61eb4da
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 85 deletions.
1 change: 1 addition & 0 deletions src/balena-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ export interface Device {
id: number;
actor: number;
api_heartbeat_state: 'online' | 'offline' | 'timeout' | 'unknown';
last_api_heartbeat_state_change_event: DateString | null;
uuid: string;
local_id: string | null;
device_name: string | null;
Expand Down
8 changes: 7 additions & 1 deletion src/balena.sbvr
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ Term: known issue list
Term: label name
Concept Type: Short Text (Type)

Term: last api heartbeat state change event
Concept Type: Date Time (Type)

Term: last connectivity event
Concept Type: Date Time (Type)

Expand Down Expand Up @@ -365,6 +368,9 @@ Term: device
Necessity: each device has exactly one api heartbeat state
Definition: "online" or "offline" or "timeout" or "unknown"

Fact type: device has last api heartbeat state change event
Necessity: each device has at most one last api heartbeat state change event.

Fact type: device has env var name
Term Form: device environment variable
Database Table Name: device environment variable
Expand Down Expand Up @@ -440,7 +446,7 @@ Fact type: user (Auth) has public key
-- user public key

Fact type: user public key has title
Necessity: each user public key has exactly one title
Necessity: each user public key has exactly one title


-- application type
Expand Down
9 changes: 9 additions & 0 deletions src/features/device-heartbeat/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { hooks } from '@balena/pinejs';

hooks.addPureHook('PATCH', 'resin', 'device', {
POSTPARSE: ({ request }) => {
if (request.values.api_heartbeat_state != null) {
request.values.last_api_heartbeat_state_change_event = new Date();
}
},
});
1 change: 1 addition & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import './features/application-types/hooks';
import './features/ci-cd/hooks';
import './features/cascade-delete/hooks';
import './features/devices/hooks';
import './features/device-heartbeat/hooks';
import './features/device-types/hooks';
import './features/device-urls/hooks';
import './features/hostapp/hooks';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "device"
ADD COLUMN IF NOT EXISTS "last api heartbeat state change event" TIMESTAMP NULL;
Loading

0 comments on commit 61eb4da

Please sign in to comment.