summaryrefslogtreecommitdiffstats
path: root/server/bin
diff options
context:
space:
mode:
authorChristian Hofmaier2019-04-18 04:24:47 +0200
committerChristian Hofmaier2019-04-18 04:24:47 +0200
commitc396c8da8825d9025ecb10d8810c9da5a7a9fd9a (patch)
tree9b8866894efa42e84368c8e8a450038c5eb5830d /server/bin
parent[wolhelper] add sanity checks (diff)
downloadbas-c396c8da8825d9025ecb10d8810c9da5a7a9fd9a.tar.gz
bas-c396c8da8825d9025ecb10d8810c9da5a7a9fd9a.tar.xz
bas-c396c8da8825d9025ecb10d8810c9da5a7a9fd9a.zip
[scheduler] allow timeouts greater than 25 days
Diffstat (limited to 'server/bin')
-rw-r--r--server/bin/scheduler.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/server/bin/scheduler.js b/server/bin/scheduler.js
index f13e329..dab37a4 100644
--- a/server/bin/scheduler.js
+++ b/server/bin/scheduler.js
@@ -4,6 +4,7 @@ global.__appdir = path.join(__dirname, '..')
const db = require(path.join(__appdir, 'lib', 'sequelize'))
const groupHelper = require(path.join(__appdir, 'lib', 'grouphelper'))
const wolHelper = require(path.join(__appdir, 'lib', 'wolhelper'))
+const setTimeoutAt = require('safe-timers').setTimeoutAt
const zmq = require('zeromq')
const socket = zmq.socket('pull')
socket.bindSync('ipc:///tmp/bas_zeromq_events')
@@ -26,7 +27,7 @@ async function calcNextWake (id) {
// Event got deleted or was updated to be not wakeonlan anymore
if (event === null || !event.wakeonlan) {
- clearTimeout(runningTimeouts[id])
+ runningTimeouts[id].clear()
delete runningTimeouts[id]
return
}
@@ -36,13 +37,9 @@ async function calcNextWake (id) {
var now = new Date()
if (!times.repetitive) {
- var start = new Date(times.start * 1000)
- if (start > now) {
- // 1. Calculate next wake
- nextWake = start - now
-
- // 2. Set timeout
- runningTimeouts[id] = setTimeout(function () {
+ nextWake = new Date(times.start * 1000)
+ if (nextWake > now) {
+ runningTimeouts[id] = setTimeoutAt(function () {
wakeUpClients(id)
}, nextWake)
}
@@ -59,7 +56,7 @@ async function calcNextWake (id) {
}, nextWake)
*/
}
- if (nextWake > 0) console.log('Scheduled event ' + event.name + ' in ' + nextWake + 'ms')
+ if (nextWake > now) console.log('Scheduled event ' + event.name + ' at ' + nextWake)
}
// Wake all clients of event