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

Update device instead of upsert so that we don't lose data between unplugs.

This commit is contained in:
Simo Kinnunen 2014-03-18 17:59:12 +09:00
parent 912dd6b58a
commit dc076c6b15

View file

@ -52,20 +52,24 @@ dbapi.saveDeviceLog = function(serial, entry) {
}
dbapi.saveDevice = function(serial, device) {
return db.run(r.table('devices').insert({
serial: serial
, present: true
, provider: device.provider
, owner: null
, status: device.status
, ready: false
, statusChangedAt: r.now()
, createdAt: r.now()
, lastHeartbeatAt: r.now()
}
, {
upsert: true
}))
var data = {
present: true
, provider: device.provider
, owner: null
, status: device.status
, ready: false
, statusChangedAt: r.now()
, createdAt: r.now()
, lastHeartbeatAt: r.now()
}
return db.run(r.table('users').get(serial).update(data))
.then(function(stats) {
if (stats.skipped) {
data.serial = serial
return db.run(r.table('devices').insert(data))
}
return stats
})
}
dbapi.saveDeviceStatus = function(serial, status) {