cron jobs starting

This commit is contained in:
Senad Uka
2017-01-05 15:39:34 +01:00
parent b4da425241
commit 070a1071c9
3 changed files with 36 additions and 1 deletions

View File

@@ -40,5 +40,24 @@ Meteor.zoblak.server = {
result = {}
};
return result;
},
on_all_controllers: function(whatToDo) {
var ids = ControllerState.find({}, {
fields: {
'controller_id': 1
}
}).map(function(cid) {
return cid.controller_id
});
for (var index in ids) {
var controller_id = ids[index];
try {
whatToDo(controller_id);
} catch(err) {
console.log('Cannot call ', whatToDo, controller_id, err);
}
}
}
}

View File

@@ -158,6 +158,7 @@ function saveAlarmSettings(controller_id, minTemperature, maxTemperature, timeou
'config.sms4': smsNumbers[3]
}
});
var jobName = "automatic_alarm_" + controller_id;
SyncedCron.remove(jobName);

View File

@@ -2,6 +2,21 @@ if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
SyncedCron.start();
Meteor.zoblak.server.on_all_controllers(function(controller_id) {
var jobName = "automatic_alarm_" + controller_id;
SyncedCron.remove(jobName);
SyncedCron.add({
name: jobName,
schedule: function(parser) {
return parser.text('every 10 seconds');
},
job: function() {
reactToAlarmData(controller_id);
}
});
});
});
@@ -23,7 +38,7 @@ if (Meteor.isServer) {
tankLevel2: this.bodyParams.tankLevel2,
tankLevel3: this.bodyParams.tankLevel3,
tankLevel4: this.bodyParams.tankLevel4,
tankFull: this.bodyParams.tankFull,
tankFull: this.bodyParams.tankFull,
startPumpingAt: this.bodyParams.startPumpingAt,
stopPumpingAt: this.bodyParams.stopPumpingAt,
owner: this.bodyParams.owner,