Skip to content

Commit

Permalink
Fix continuous suspension of the timeago alerts
Browse files Browse the repository at this point in the history
The default hearbeat-setting is 60 seconds, so the delta between two
timeago-checks will always be >15 seconds and the timeago-alarms will
always be suspended (that's what Papertrail also shows).

To fix this, make the delta-check heartbeat-setting-dependant and also simplify
the code by using just 1 variable.
  • Loading branch information
fibbers committed Oct 31, 2019
1 parent 9c42fed commit 7a4cc71
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/plugins/timeago.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
var levels = require('../levels');
var times = require('../times');
var lastChecked = new Date();
var lastSuspendTime = new Date("1900-01-01");

function init(ctx) {
var translate = ctx.language.translate;
var heartbeatMs = ctx.settings.heartbeat * 1000;

var timeago = {
name: 'timeago',
Expand Down Expand Up @@ -64,21 +64,14 @@ function init(ctx) {
};

timeago.checkStatus = function checkStatus(sbx) {

// Check if the app has been suspended; if yes, snooze data missing alarmn for 15 seconds
var now = new Date();
var delta = now.getTime() - lastChecked.getTime();
lastChecked = now;

if (delta > 15 * 1000) { // Looks like we've been hibernating
lastSuspendTime = now;
}

var timeSinceLastSuspended = now.getTime() - lastSuspendTime.getTime();

if (timeSinceLastSuspended < (10 * 1000)) {

console.log('Hibernation detected, suspending timeago alarm');
// More than 2 heartbeats since last call: looks like we've been hibernating
if (delta > 2 * heartbeatMs) {
console.log('Hibernation detected because of 2 missed hearbeats, suspending timeago alarm. heartbeatMs:', heartbeatMs, 'delta:', delta);
return 'current';
}

Expand Down

0 comments on commit 7a4cc71

Please sign in to comment.