Skip to content

Commit

Permalink
Fix check user presence, the function is async and we need to wait be…
Browse files Browse the repository at this point in the history
…fore using the variable
  • Loading branch information
Pierre-Gilles committed Mar 27, 2019
1 parent e1bcf4f commit eb41bc3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions api/core/task/task.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ module.exports = function(cb){
gladys.param.getValue('USER_CHECK_PRESENCE_FREQUENCY')
.catch(() => DEFAULT_CHECK_USER_PRESENCE_FREQUENCY)
.then((checkFrequency) => {
setInterval(function() {
if(userHasCheckPresence()){
setInterval(async function() {
const shouldCheckUserPresence = await userHasCheckPresence();
if(shouldCheckUserPresence){
gladys.house.checkUsersPresence();
}
}, checkFrequency * 60 * 1000);
Expand All @@ -91,13 +92,13 @@ module.exports = function(cb){

function userHasCheckPresence(){
return gladys.param.getValue('CHECK_USER_PRESENCE')
.catch((err) => {
.catch(async (err) => {
if(err.message === 'Param CHECK_USER_PRESENCE not found'){
gladys.param.setValue({name: 'CHECK_USER_PRESENCE', value: 'false', type: 'secret'});
await gladys.param.setValue({name: 'CHECK_USER_PRESENCE', value: 'false', type: 'secret'});
} else {
sails.log.err(err);
}
return false;
})
.then((value) => value);
.then((value) => (value === true));
}

0 comments on commit eb41bc3

Please sign in to comment.