Writing points to instance-specific file.
This commit is contained in:
parent
d9f1181fcb
commit
d56b3f456b
|
@ -8,6 +8,7 @@ const fs = require('fs').promises;
|
|||
const logger = require('simple-node-logger').createSimpleLogger();
|
||||
const { argv } = require('yargs');
|
||||
|
||||
const instance = process.env.NODE_APP_INSTANCE || 'main';
|
||||
const points = {};
|
||||
|
||||
logger.setLevel(argv.level || 'info');
|
||||
|
@ -66,7 +67,7 @@ async function setPoints(gameKey, user, value, mode = 'add') {
|
|||
points[gameKey][userKey] = value;
|
||||
}
|
||||
|
||||
await fs.writeFile('./points.json', JSON.stringify(points, null, 4));
|
||||
await fs.writeFile(`./points-${instance}.json`, JSON.stringify(points, null, 4));
|
||||
}
|
||||
|
||||
function getPoints(game, { user, room }) {
|
||||
|
@ -188,14 +189,14 @@ const messageHandlers = {
|
|||
|
||||
async function initPoints() {
|
||||
try {
|
||||
const pointsFile = await fs.readFile('./points.json', 'utf-8');
|
||||
const pointsFile = await fs.readFile(`./points-${instance}.json`, 'utf-8');
|
||||
|
||||
Object.assign(points, JSON.parse(pointsFile));
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
logger.info('Creating new points file');
|
||||
|
||||
await fs.writeFile('./points.json', '{}');
|
||||
await fs.writeFile(`./points-${instance}.json`, '{}');
|
||||
initPoints();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue