Merge remote-tracking branch 'upstream/release-7.5.0' into chore/merge-release-into-dev-21-16-12

This commit is contained in:
Taranto 2021-12-16 13:38:43 +00:00
commit e9b2280fc3
33 changed files with 250 additions and 64 deletions

View file

@ -85,12 +85,8 @@ function buildAlerts (pings, balances, events, devices) {
alerts.general = _.filter(r => !r.deviceId, balances)
_.forEach(device => {
const deviceId = device.deviceId
const deviceName = device.name
const deviceEvents = events.filter(function (eventRow) {
return eventRow.device_id === deviceId
})
const ping = pings[deviceId] || []
const stuckScreen = checkStuckScreen(deviceEvents, deviceName)
const stuckScreen = checkStuckScreen(events, device)
alerts.devices = _.set([deviceId, 'balanceAlerts'], _.filter(
['deviceId', deviceId],
@ -98,7 +94,7 @@ function buildAlerts (pings, balances, events, devices) {
), alerts.devices)
alerts.devices[deviceId].deviceAlerts = _.isEmpty(ping) ? stuckScreen : ping
alerts.deviceNames[deviceId] = deviceName
alerts.deviceNames[deviceId] = device.name
}, devices)
return alerts
@ -110,12 +106,13 @@ function checkPings (devices) {
return _.zipObject(deviceIds)(pings)
}
function checkStuckScreen (deviceEvents, machineName) {
const sortedEvents = _.sortBy(
utils.getDeviceTime,
_.map(utils.parseEventNote, deviceEvents)
)
const lastEvent = _.last(sortedEvents)
function checkStuckScreen (deviceEvents, machine) {
const lastEvent = _.pipe(
_.filter(e => e.device_id === machine.deviceId),
_.sortBy(utils.getDeviceTime),
_.map(utils.parseEventNote),
_.last
)(deviceEvents)
if (!lastEvent) return []
@ -125,6 +122,7 @@ function checkStuckScreen (deviceEvents, machineName) {
if (isIdle) return []
const age = Math.floor(lastEvent.age)
const machineName = machine.name
if (age > STALE_STATE) return [{ code: STALE, state, age, machineName }]
return []