cron jobs starting
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +158,7 @@ function saveAlarmSettings(controller_id, minTemperature, maxTemperature, timeou
|
||||
'config.sms4': smsNumbers[3]
|
||||
}
|
||||
});
|
||||
|
||||
var jobName = "automatic_alarm_" + controller_id;
|
||||
|
||||
SyncedCron.remove(jobName);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user