Skip to content
Snippets Groups Projects
Verified Commit c19d3b4b authored by Erick Hitter's avatar Erick Hitter
Browse files

On second thought, kill the process when unregistered locks are found, as...

On second thought, kill the process when unregistered locks are found, as state is not reliable or repairable.
parent 1ace020f
No related branches found
No related tags found
No related merge requests found
......@@ -33,31 +33,16 @@ var ret = {
'msg': ''
};
// Register a given lock if it can be located
function registerLock( lockName, lockConfig ) {
augustctl.scan( lockConfig.lockUuid ).then( function( peripheral ) {
var lock = new augustctl.Lock(
peripheral,
lockConfig.offlineKey,
lockConfig.offlineKeyOffset
);
app.set('lock' + lockName, lock);
} );
}
// Get lock instance
function getLockInstance( lockName, res ) {
var lock = app.get( 'lock' + lockName );
if ( lock ) {
return lock;
} else if ( 'object' === typeof config[ lockName ] ) {
// If a valid lock exists but isn't registered, kill the process because its state is unpredictable
process.exit();
} else {
if ( 'object' === typeof config[ lockName ] ) {
console.log( 'Loading MISSING config for lock "%s" (%s)', lockName, config[ lockName ].lockUuid );
registerLock( lockName, config[ lockName ] );
}
clearCaches( lockName );
res.sendStatus( 400 );
return false;
}
......@@ -189,7 +174,15 @@ Object.keys( config ).forEach( function( lockName ) {
console.log( 'Loading config for lock "%s" (%s)', lockName, lockConfig.lockUuid );
registerLock( lockName, lockConfig );
augustctl.scan( lockConfig.lockUuid ).then( function( peripheral ) {
var lock = new augustctl.Lock(
peripheral,
lockConfig.offlineKey,
lockConfig.offlineKeyOffset
);
app.set( 'lock' + lockName, lock );
} );
} );
// Start Express server
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment