This commit is contained in:
Ralfs 2021-04-10 02:13:35 +03:00
parent 4a1e0782fd
commit 6eef5a55e7
2 changed files with 4 additions and 6 deletions

View File

@ -5,7 +5,7 @@ dotenv.config();
export default {
dbConnectionString: (process.env.NODE_ENV == 'production') ?
`mongodb://${process.env.DB_USER}:${encodeURIComponent(process.env.DB_PASS || '')}@${process.env.DB_HOSTS}/${process.env.DB}${process.env.DB_OPTIONS}`:
'mongodb://localhost:27017',
'mongodb://localhost:27017/mango_alerts',
db: process.env.DB || '',
port: process.env.PORT || 3000,

View File

@ -38,7 +38,6 @@ router.get('/', async(ctx, next) => {
})
router.post('/alerts', async(ctx, next) => {
sendLogsToDiscord('Alert called', null);
try {
const alert = ctx.request.body;
await validateMarginAccount(client, connection, dexProgramId, alert);
@ -57,7 +56,7 @@ router.post('/alerts', async(ctx, next) => {
throw new UserError('Invalid alert provider');
}
alert.open = true;
alert.timestamp = new Date();
alert.timestamp = Date.now();
ctx.db.collection('alerts').insertOne(alert);
} catch (e) {
let errorMessage = 'Something went wrong';
@ -105,9 +104,8 @@ const runCron = async () => {
}
}
});
const expiryTime = new Date( Date.now() - (1000 * 60 * 1) ); // 15 Minutes
console.log(expiryTime);
db.collection('alerts').deleteMany({ tgChatId: { $exists: false }, timestamp: { '$lt': expiryTime } });
const expiryTime = Date.now() - (1000 * 60 * 15); // 15 Minutes
db.collection('alerts').deleteMany({ tgChatId: { '$exists': false }, timestamp: { '$lt': expiryTime } });
} catch (e) {
sendLogsToDiscord(null, e);
}