-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add features to prevent sleeping, fixes #2
- Loading branch information
Showing
4 changed files
with
38 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const SaveVehiclePositions = require('./protobufs/exec-vp') | ||
|
||
// Recursively refresh VehiclePositions | ||
const RefreshVP = () => SaveVehiclePositions().then(() => { | ||
setTimeout(RefreshVP, 10000) | ||
}) | ||
|
||
module.exports = RefreshVP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const RefreshVP = require('../functions/refresh-vp') | ||
|
||
const filesrc = dir => path.join(process.cwd(), dir) | ||
|
||
const getLastUpdateTime = () => new Promise((resolve, reject) => { | ||
fs.stat(filesrc('./tmp/realtime/VehiclePositions.pb'), (err, stats) => { | ||
if (err) reject(err) | ||
const timestamp = new Date(stats.mtime).valueOf() | ||
resolve(timestamp) | ||
}) | ||
}) | ||
|
||
module.exports = async (req, res, next) => { | ||
const lut = await getLastUpdateTime() | ||
|
||
// 20 seconds without an update | ||
// so trigger recursion loop again | ||
if (Date.now() - 20000 > lut) { | ||
RefreshVP() | ||
} | ||
|
||
next() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters