Browse Source

Add daily auto restart

shorten
benji7425 3 years ago
parent
commit
f996eb363b
  1. 2
      discord-bot-core/internal-config.json
  2. 33
      discord-bot-core/monitor.js
  3. 7
      package-lock.json
  4. 3
      package.json

2
discord-bot-core/internal-config.json

@ -1,5 +1,7 @@
{
"dbCompactionSchedule": "0 0 0,3,6,9 * * *",
"restartSchedule": "0 0 0 * * *",
"restartTimeout": 5000,
"website": "https://benji7425.github.io",
"discordInvite": "https://discord.gg/SSkbwSJ",
"debugIgnores": [

33
discord-bot-core/monitor.js

@ -0,0 +1,33 @@
const { fork } = require("child_process");
const CronJob = require("cron").CronJob;
const DiscordUtil = require("./Util.js");
// @ts-ignore
const InternalConfig = require("./internal-config.json");
let instance;
restart();
new CronJob(InternalConfig.restartSchedule, restart, null, true);
function restart() {
ensureKilledInstance()
.then(bootstrapNewInstance)
.catch(DiscordUtil.dateError);
}
function bootstrapNewInstance() {
instance = fork(process.argv[2]);
}
function ensureKilledInstance() {
return new Promise((resolve, reject) => {
if (instance) {
instance.kill();
DiscordUtil.dateLog(`Killed existing instance for scheduled restart in ${InternalConfig.restartTimeout / 1000} sec`);
setTimeout(resolve, InternalConfig.restartTimeout);
}
else
resolve();
});
}

7
package-lock.json

@ -1,9 +1,14 @@
{
"name": "discord-bot-rss-feed",
"version": "3.2.2",
"version": "3.3.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@types/node": {
"version": "9.3.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-9.3.0.tgz",
"integrity": "sha512-wNBfvNjzsJl4tswIZKXCFQY0lss9nKUyJnG6T94X/eqjRgI2jHZ4evdjhQYBSan/vGtF6XVXPApOmNH2rf0KKw=="
},
"acorn": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-1.2.2.tgz",

3
package.json

@ -3,9 +3,10 @@
"main": "app/index.js",
"scripts": {
"postinstall": "cd ./discord-bot-core && npm install",
"start": "node app/index.js --name=rss-feed"
"start": "node discord-bot-core/monitor.js ./app/index.js --name=rss-feed"
},
"dependencies": {
"@types/node": "9.3.0",
"camo": "git+https://github.com/scottwrobinson/camo.git",
"discord.js": "11.2.0",
"get-urls": "7.0.0",

Loading…
Cancel
Save