mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
fix bug on taking control of a device: set a lock for exclusive access (#650)
* fix bug on taking control of a device: set a lock for exclusive access Signed-off-by: Denis barbaron <denis.barbaron@orange.com> * update the locking function Signed-off-by: Denis barbaron <denis.barbaron@orange.com> --------- Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright © 2019 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
|
||||
* Copyright © 2019,2023 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
|
||||
**/
|
||||
|
||||
var r = require('rethinkdb')
|
||||
@@ -278,6 +278,30 @@ dbapi.lockBookableDevice = function(groups, serial) {
|
||||
, Math.random() * 500 + 50)
|
||||
}
|
||||
|
||||
dbapi.lockDeviceByCurrent = function(groups, serial) {
|
||||
function wrappedlockDeviceByCurrent() {
|
||||
return db.run(r.table('devices').get(serial).update({group: {lock:
|
||||
r.branch(
|
||||
r.row('group')('lock')
|
||||
.eq(false)
|
||||
.and(r.expr(groups)
|
||||
.setIntersection([r.row('group')('id')])
|
||||
.isEmpty()
|
||||
.not())
|
||||
, true
|
||||
, r.row('group')('lock'))
|
||||
}}, {returnChanges: true}))
|
||||
.then(function(stats) {
|
||||
return apiutil.lockDeviceResult(stats, dbapi.loadDeviceByCurrent, groups, serial)
|
||||
})
|
||||
}
|
||||
|
||||
return apiutil.setIntervalWrapper(
|
||||
wrappedlockDeviceByCurrent
|
||||
, 10
|
||||
, Math.random() * 500 + 50)
|
||||
}
|
||||
|
||||
dbapi.lockDeviceByOrigin = function(groups, serial) {
|
||||
function wrappedlockDeviceByOrigin() {
|
||||
return db.run(r.table('devices').get(serial).update({group: {lock:
|
||||
@@ -1362,6 +1386,15 @@ dbapi.loadBookableDevice = function(groups, serial) {
|
||||
})
|
||||
}
|
||||
|
||||
dbapi.loadDeviceByCurrent = function(groups, serial) {
|
||||
return db.run(r.table('devices').getAll(serial).filter(function(device) {
|
||||
return r.expr(groups).contains(device('group')('id'))
|
||||
}))
|
||||
.then(function(cursor) {
|
||||
return cursor.toArray()
|
||||
})
|
||||
}
|
||||
|
||||
dbapi.loadDeviceByOrigin = function(groups, serial) {
|
||||
return db.run(r.table('devices').getAll(serial).filter(function(device) {
|
||||
return r.expr(groups).contains(device('group')('origin'))
|
||||
|
||||
Reference in New Issue
Block a user