This works but periodically I get the attached error. I assume it's because the check (if condition) is made in the moment the new batch process is just about to be called but it's name not yet in the currentJobNames array. Can this be somehow avoided?
This ist my code:
- Code: Select all
var currentJobNames = plugins.scheduler.getCurrentJobNames();
if (currentJobNames.indexOf('timTimetableBatchProcess') < 0) {
globals.timTimetableBatchProcess(); // Batch process 'timTimetableBatchProcess' is not running, start it
}
... and the batch process code.
- Code: Select all
function timTimetableBatchProcess() {
var startDate = new Date();
startDate.setTime(startDate.getTime() + 10000); // Start the batch job every 10'000 milliseconds
var endDate = new Date(startDate.getTime() + 100000); // Set end time greater than start time to avoid running multiple copies of this method
plugins.scheduler.addJob('timTimetableBatchProcess', startDate, globals.timTimetableBatchProcess, 0, 0, endDate);
if ('TimClassTimetable' in forms) {
forms.TimClassTimetable.refresh(); // Refresh the class timetable
}
if ('TimTeacherTimetable' in forms) {
forms.TimTeacherTimetable.refresh(); // Refresh the teacher timetable
}
}