-
-
Save etaques/3db634dc07e9e0a7f7c082d754e8e86c to your computer and use it in GitHub Desktop.
Restart Web3TokenCharting on crash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require('dotenv').config(); | |
| // initialize mongodb | |
| const Transactions = require('../server/models/history_transactions'); | |
| var configDB = require('../server/config/database'); | |
| const mongoose = require('mongoose'); | |
| console.log( configDB.url ) | |
| mongoose.connect(configDB.url, { | |
| autoIndex: false, | |
| useNewUrlParser: true, | |
| useUnifiedTopology: true | |
| }).then(() => { console.log('14MongoDB is connected') }) | |
| .catch(err => { | |
| console.log('MongoDB connection unsuccessful'); | |
| console.log(err) | |
| }); | |
| const { exec } = require('child_process'); | |
| function sleep(ms) { | |
| return new Promise(resolve => setTimeout(resolve, ms)); | |
| } | |
| (async () => { | |
| let transactionsCount = await Transactions.countDocuments(); | |
| while( true ){ | |
| let newTransactionsCount = await Transactions.countDocuments(); | |
| console.log(`[tx count] new: ${newTransactionsCount} | old: ${transactionsCount}` ); | |
| if( transactionsCount >= newTransactionsCount ) { | |
| exec('pm2 restart 17', (err, stdout, stderr) => { | |
| if (err) { | |
| // node couldn't execute the command | |
| console.log('Could not execute command', err) | |
| return; | |
| } | |
| console.log('Restarted process') | |
| }); | |
| } | |
| transactionsCount = newTransactionsCount; | |
| await sleep( 60 * 1000 ); | |
| } | |
| })(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment