Author Topic: Scheduling event error  (Read 150 times)

redpoll123

  • Newbie
  • *
  • Posts: 17
  • Country: us
Scheduling event error
« on: August 16, 2019, 01:14:40 PM »
A scheduled event was missed several times due to a "SCHEDULING EVENT ERROR".

I did not see any conflicts/collisions with other events or node activity in the log at those times,
so was wondering about the message  "cannot schedule event in ... (less than 1s)" .
 
Code: [Select]
[08-15-19_06:55:23.110] [LOG]    post: /home/pi/gateway/data/db/0068_RSSI.bin[1565880923,-90]
[08-15-19_06:55:23.115] [LOG]       [68] DB-Updates:1
[08-15-19_07:01:59.451] [LOG]    **** RUNNING SCHEDULED EVENT - nodeId:2 event:raspberry_Poll7_AM_Post...
[08-15-19_07:01:59.455] [ERROR]  **** SCHEDULING EVENT ERROR - nodeId:2 event:raspberry_Poll7_AM_Post cannot schedule event in 545ms (less than 1s)
[08-15-19_07:03:20.745] [LOG]    >: [155] 25.64cm BAT:3.62   [RSSI:-65][ACK-sent]

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5938
  • Country: us
    • LowPowerLab
Re: Scheduling event error
« Reply #1 on: August 16, 2019, 01:19:34 PM »
Some details about the event would be helpful.
And the code.
Actually, everything related to that event so I don't ask twice.

redpoll123

  • Newbie
  • *
  • Posts: 17
  • Country: us
Re: Scheduling event error
« Reply #2 on: August 16, 2019, 01:57:19 PM »
The event raspberry_Poll7_AM_Post runs once a day and
sends a html request to a cell phone which in turn sends SMS text "Gateway OK".
It has worked well just had several instances, recently, that did not go through and saw this error.

Here is the event and also the request function.
 
(Thank you duane1 for pointing out the Tasker app!)

Code: [Select]
raspberry_Poll7_AM_Post: {
    label: 'Send Gateway AOK HTML POST @ 7 AM every day',
    icon: 'clock',
    descr: 'Send HTML POST every day at 7 AM to show Gateway is still running ',
    nextSchedule: function(node) {
        return exports.timeoutOffset(7, 2);
    }, //ie 7:00 (7am)
    scheduledExecute: function(node) {

        exports.taskerRequest('alarming=Gateway OK @ ' + (new Date().toLocaleTimeString() + ' : '));
        //         db.update({ _id: node._id }, { $set : node}, {}, function (err, numReplaced) { console.log('   ['+node._id+'] DB-Updates:' + numReplaced);});
        /*save lastSMS timestamp to DB*/

    }
},

Code: [Select]
exports.taskerRequest = function(triggerWord) {
var phoneIP = settings.general.ipPhone.value;
    request.post({
         headers: {'content-type' : 'application/x-www-form-urlencoded'},
         url:'http://'+phoneIP,     // Galaxy S3
         body: triggerWord },
         function(error,response,body){ }
      );
    //request.post({
        //headers: {'content-type' : 'application/x-www-form-urlencoded'},
        //url:'http://192.168.1.127:8765',     // ZTE Maven
        //body: triggerWord },
        //function(error,response,body){ }
    //);
 
  }

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5938
  • Country: us
    • LowPowerLab
Re: Scheduling event error
« Reply #3 on: August 19, 2019, 12:33:55 PM »
What type of Pi are you using?
Does this happen the first time this event runs? (ex. after a gateway app restart)
Or does it happen randomly (without gateway app restarts)?

I'm not quite sure what might cause it. It's suggesting some discrepancy in how the next run timestamp is calculated.
Could you try replacing the timeoutOffset function with this, and see if it makes any difference?

Code: [Select]
exports.timeoutOffset = function(hour, minute, second, offset) {
  var result = new Date().setHours(hour,minute,second || 0, 0);
  var now = new Date().getTime();
  result = result < now ? (result + exports.ONEDAY) : result;
  result -= now;
  if (exports.isNumeric(offset)) result += offset;
  return result;
}

redpoll123

  • Newbie
  • *
  • Posts: 17
  • Country: us
Re: Scheduling event error
« Reply #4 on: August 20, 2019, 12:02:51 PM »
Pi 3 running Stretch with Gateway ver 9.0.0 (built on Pi3 B+ then the sdcard moved to a Pi 3)

Happened as first time and also after event had run OK previously.

Changed the timeoutOffset function and will let it run.

redpoll123

  • Newbie
  • *
  • Posts: 17
  • Country: us
Re: Scheduling event error
« Reply #5 on: August 31, 2019, 12:21:29 PM »
The timeoutOffset function was replaced and the Scheduling event error still happens occasionally.
The error also happens on another gateway running on a Pi Zero W.

This log entry shows an instance where the event runs and evidently the event is scheduled a second later which then runs and is scheduled again with the correct time.

Code: [Select]
[08-31-19_06:12:16.275] [INFO]   NEW CONNECTION FROM 192.168.1.2
[08-31-19_07:04:58.131] [LOG]    **** RUNNING SCHEDULED EVENT - nodeId:2 event:raspberry_Poll7_AM_Post...
[08-31-19_07:04:58.285] [LOG]    **** SCHEDULING EVENT - nodeId:2 event:raspberry_Poll7_AM_Post to run in ~1s
[08-31-19_07:04:58.371] [LOG]       [2] DB-Updates:1
[08-31-19_07:05:00.004] [LOG]    **** RUNNING SCHEDULED EVENT - nodeId:2 event:raspberry_Poll7_AM_Post...
[08-31-19_07:05:00.020] [LOG]    **** SCHEDULING EVENT - nodeId:2 event:raspberry_Poll7_AM_Post to run in ~23h59m
[08-31-19_07:05:00.048] [LOG]       [2] DB-Updates:1