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:
parent
912dd6b58a
commit
dc076c6b15
1 changed files with 18 additions and 14 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue