Skip to content

Commit ffcb820

Browse files
committed
Fix Copilot suggestions in metrics-hooks.js
Signed-off-by: matanbaruch <matan.baruch@unity3d.com>
1 parent 8e22469 commit ffcb820

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

lib/util/metrics-hooks.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@ class MetricsHooks {
2424
static onDeviceStatusChanged(device) {
2525
// Update device status metrics
2626
try {
27-
let status = 'offline'
27+
const previousStatus = device.previousStatus || 'offline';
28+
let newStatus = 'offline';
2829
if (device.present) {
29-
status = device.owner ? 'busy' : 'available'
30+
newStatus = device.owner ? 'busy' : 'available';
31+
}
32+
// Update metrics if the status has changed
33+
if (previousStatus !== newStatus) {
34+
// Decrement the count for the previous status
35+
metrics.metrics.devicesByStatus.dec({ status: previousStatus });
36+
// Increment the count for the new status
37+
metrics.metrics.devicesByStatus.inc({ status: newStatus });
38+
log.debug('Device status changed:', device.serial, 'from:', previousStatus, 'to:', newStatus);
3039
}
31-
32-
// This is a simple approximation - in a real implementation
33-
// you'd want to track the previous status and update accordingly
34-
log.debug('Device status changed:', device.serial, 'status:', status)
3540
}
3641
catch (error) {
37-
log.error('Error updating device status metrics:', error)
38-
}
42+
log.error('Error updating device status metrics:', error); }
3943
}
4044

4145
static onUserAdded() {

0 commit comments

Comments
 (0)