improve parser
This commit is contained in:
parent
3157c993bf
commit
6d77138ebd
@ -5,7 +5,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node src/index.js"
|
||||
"start": "bash -x watchdog.sh"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
@ -4,9 +4,17 @@ const fs = require('fs/promises');
|
||||
const logger = require('./logger.js');
|
||||
|
||||
function parseEvent(evt) {
|
||||
if (evt?.action) {
|
||||
try {
|
||||
evt = JSON.parse(evt)
|
||||
} catch (e) {
|
||||
logger.error(`failed to parse event=${evt}`)
|
||||
}
|
||||
if (typeof evt?.action === "number") {
|
||||
logger.debug(`event with action=${evt.action}`);
|
||||
if (evt.action === 0) return false; // heartbeat
|
||||
if (evt.action === 15) return true; // chat message
|
||||
} else {
|
||||
logger.warn(`event with NO ACTION. evt=${JSON.stringify(evt)} ${typeof evt}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
17
services/scout/watchdog.sh
Normal file
17
services/scout/watchdog.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
while true; do
|
||||
echo "Starting app..."
|
||||
node src/index.js
|
||||
|
||||
exit_code=$?
|
||||
if [ $exit_code -eq 0 ]; then
|
||||
echo "Exited normally. Not restarting."
|
||||
break
|
||||
fi
|
||||
|
||||
echo "App crashed (exit code $exit_code). Restarting in 2 seconds..."
|
||||
sleep 2
|
||||
done
|
Loading…
x
Reference in New Issue
Block a user