task scheduling, logging fixes
This commit is contained in:
parent
ae795f3a90
commit
5dc2a3fa0c
|
@ -11,6 +11,7 @@
|
|||
"dependencies": {
|
||||
"body-parser": "^1.20.2",
|
||||
"express": "^4.18.2",
|
||||
"node-cron": "^3.0.2",
|
||||
"pino": "^8.15.0",
|
||||
"pino-http": "^8.4.0",
|
||||
"promised-sqlite3": "^2.1.0",
|
||||
|
@ -1412,6 +1413,17 @@
|
|||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz",
|
||||
"integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ=="
|
||||
},
|
||||
"node_modules/node-cron": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.2.tgz",
|
||||
"integrity": "sha512-iP8l0yGlNpE0e6q1o185yOApANRe47UPbLf4YxfbiNHt/RU5eBcGB/e0oudruheSf+LQeDMezqC5BVAb5wwRcQ==",
|
||||
"dependencies": {
|
||||
"uuid": "8.3.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "2.6.12",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
||||
|
@ -2285,6 +2297,14 @@
|
|||
"node": ">= 0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "8.3.2",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/vary": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
"dependencies": {
|
||||
"body-parser": "^1.20.2",
|
||||
"express": "^4.18.2",
|
||||
"node-cron": "^3.0.2",
|
||||
"pino": "^8.15.0",
|
||||
"pino-http": "^8.4.0",
|
||||
"promised-sqlite3": "^2.1.0",
|
||||
|
|
|
@ -2,6 +2,7 @@ import express from "express";
|
|||
import bodyParser from "body-parser";
|
||||
import logger from "./logger.mjs";
|
||||
import pinoHTTP from 'pino-http'
|
||||
import start from "./start.mjs";
|
||||
const app = express()
|
||||
const port = 4000
|
||||
app.use(bodyParser.json())
|
||||
|
@ -11,20 +12,19 @@ app.use(
|
|||
})
|
||||
)
|
||||
app.post('/api', (req,res) => {
|
||||
console.log("webhook received:")
|
||||
console.dir(req.body.body.note.text)
|
||||
logger.info("webhook received:",req.body.body.note.text)
|
||||
res.sendStatus(200)
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`listening on port ${port}`)
|
||||
logger.trace(`listening on port ${port}`)
|
||||
})
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
// log the exception
|
||||
logger.fatal(err, 'uncaught exception detected');
|
||||
// shutdown the server gracefully
|
||||
server.close(() => {
|
||||
app.close(() => {
|
||||
process.exit(1); // then exit
|
||||
});
|
||||
|
||||
|
@ -35,3 +35,5 @@ process.on('uncaughtException', (err) => {
|
|||
}, 1000).unref()
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
start()
|
|
@ -0,0 +1,8 @@
|
|||
import cron from 'node-cron'
|
||||
import logger from './logger.mjs';
|
||||
|
||||
export default function start(){
|
||||
cron.schedule('* * * * *', () => {
|
||||
logger.trace('running a task every minute');
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue