Skip to content

Commit

Permalink
fix add0846 issue on cold start
Browse files Browse the repository at this point in the history
  • Loading branch information
rand256 committed Jun 9, 2019
1 parent 42350ac commit 092582b
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions lib/CronScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CronScheduler = function (parameters) {
}
// todo: add some more validation maybe
let task = cron.schedule(job[2], () => {
this.vacuum.getCurrentStatus(function (err, data) {
self.vacuum.getCurrentStatus(function (err, data) {
// running ONLY when state = 8 (charging)
if (!err && data && data.state === 8) {
self.vacuum.startCleaningZone(job[3], function (err, data) {
Expand All @@ -28,40 +28,40 @@ const CronScheduler = function (parameters) {
console.log('scheduled zoned cleaning start failed', err, data);
}
});
},{timezone: this.timezone});
this.schedules.push(task);
},{timezone: self.timezone});
self.schedules.push(task);
return true;
};

this.removeSchedule = function(index) {
if (this.schedules[index]) {
let task = this.schedules[index];
if (self.schedules[index]) {
let task = self.schedules[index];
task.destroy();
this.schedules.splice(index, 1);
self.schedules.splice(index, 1);
return true;
}
return false;
};

this.resetSchedules = function() {
for (let i = this.schedules.length - 1; i >= 0 ; i--) {
this.removeSchedule(i);
for (let i = self.schedules.length - 1; i >= 0 ; i--) {
self.removeSchedule(i);
}
this.configuration.get("ztimers").forEach(task => {
this.createSchedule(task);
self.configuration.get("ztimers").forEach(task => {
self.createSchedule(task);
});
};

this.vacuum.getTimezone(function (err, data) {
if (!err) {
self.timezone = data;
}
if (self.configuration.get("ztimers") && self.configuration.get("ztimers").length) {
self.configuration.get("ztimers").forEach(job => {
self.createSchedule(job);
});
};
});
this.initSchedules = function() {
self.vacuum.getTimezone(function (err, data) {
if (!err) {
self.timezone = data;
}
self.resetSchedules();
});
};

setTimeout(() => { self.initSchedules() }, 30e3);
};

module.exports = CronScheduler;

0 comments on commit 092582b

Please sign in to comment.