mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-19 08:33:24 +02:00
Better device present/absent handling by separating it from the status event.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user