Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jan
kresus
Commits
397f64a4
Commit
397f64a4
authored
Jul 23, 2016
by
ZeHiro
Browse files
Awake Kresus server every 20minutes so that the automatic poll can occur on Raspberry PI. Fix #401
parent
6474ccc3
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/lib/poller.js
View file @
397f64a4
...
...
@@ -14,11 +14,18 @@ import { makeLogger, translate as $t, isCredentialError } from '../helpers';
let
log
=
makeLogger
(
'
poller
'
);
// Raise an event in the event loop every 20 min to maintain the process awaken
// to work around a timer bug on low-end devices like Raspberry PI
const
WAKEUP_INTERVAL
=
20
*
60
*
1000
;
class
Poller
{
constructor
()
{
this
.
t
imeout
=
null
;
this
.
runT
imeout
=
null
;
this
.
run
=
this
.
run
.
bind
(
this
);
this
.
timeToNextRun
=
null
;
this
.
wakeupInterval
=
null
;
}
programNextRun
()
{
...
...
@@ -33,12 +40,30 @@ class Poller
let
format
=
'
DD/MM/YYYY [at] HH:mm:ss
'
;
log
.
info
(
`> Next check of accounts on
${
nextUpdate
.
format
(
format
)}
`
);
if
(
this
.
t
imeout
!==
null
)
{
clearTimeout
(
this
.
t
imeout
);
this
.
t
imeout
=
null
;
if
(
this
.
runT
imeout
!==
null
)
{
clearTimeout
(
this
.
runT
imeout
);
this
.
runT
imeout
=
null
;
}
this
.
timeout
=
setTimeout
(
this
.
run
,
nextUpdate
.
diff
(
now
));
this
.
timeToNextRun
=
nextUpdate
.
diff
(
now
);
if
(
this
.
timeToNextRun
<
WAKEUP_INTERVAL
)
{
this
.
wakeupInterval
=
setTimeout
(
this
.
run
,
this
.
timeToNextRun
);
}
else
{
this
.
timeToNextRun
=
this
.
timeToNextRun
-
WAKEUP_INTERVAL
;
this
.
wakeupInterval
=
setInterval
(()
=>
{
if
(
this
.
timeToNextRun
<
WAKEUP_INTERVAL
)
{
// Clean the setInterval to ensure it to be stopped when this.run is called
if
(
this
.
wakeupInterval
!==
null
)
{
clearInterval
(
this
.
wakeupInterval
);
this
.
wakeupInterval
=
null
;
}
this
.
runTimeout
=
setTimeout
(
this
.
run
,
this
.
timeToNextRun
);
}
else
{
this
.
timeToNextRun
=
this
.
timeToNextRun
-
WAKEUP_INTERVAL
;
}
},
WAKEUP_INTERVAL
);
}
}
async
run
(
cb
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment