1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 02:09:32 +02:00

Better device present/absent handling by separating it from the status event.

This commit is contained in:
Simo Kinnunen 2014-02-03 19:42:20 +09:00
parent f432dc9fb9
commit 2086d7d439
9 changed files with 147 additions and 39 deletions

View file

@ -41,26 +41,36 @@ dbapi.saveDeviceLog = function(serial, entry) {
}))
}
dbapi.saveDeviceStatus = function(serial, status) {
return db.run(r.table('devices').get(serial).update({
status: status.status
, provider: status.provider
dbapi.saveDevice = function(serial, device) {
return db.run(r.table('devices').insert({
serial: serial
, present: true
, provider: device.provider
, status: device.status
, statusChangedAt: r.now()
, createdAt: r.now()
}
, {
upsert: true
}))
.then(function(stats) {
if (stats.skipped) {
return db.run(r.table('devices').insert({
serial: serial
, provider: status.provider
, status: status.status
, statusChangedAt: r.now()
, createdAt: r.now()
}))
}
return stats
}
dbapi.saveDeviceStatus = function(serial, status) {
return dbapi.ensureDeviceSaved(serial)
.then(function() {
return db.run(r.table('devices').get(serial).update({
status: status
, statusChangedAt: r.now()
}))
})
}
dbapi.setDeviceAbsent = function(serial) {
return db.run(r.table('devices').get(serial).update({
present: false
}))
}
dbapi.saveDeviceIdentity = function(serial, identity) {
return db.run(r.table('devices').get(serial).update({
platform: identity.platform