I hereby claim:
- I am pwhisenhunt on github.
- I am pwhisenhunt (https://keybase.io/pwhisenhunt) on keybase.
- I have a public key ASDPcgH_FgkRxCK_p1U3SEgz53PUlCKcXBWsO7nrQZN49wo
To claim this, I am signing this object:
process.on('SIGINT', () => { | |
console.log('SIGINT signal received.'); | |
let mongoClientExited = false; | |
let redisClientExited = false; | |
let expressServerExited = false; | |
function attemptToExitProcess() { | |
if (redisClientExited && mongoClientExited && expressServerExited) { | |
console.log('All connections have cleanly closed. Exiting process...'); | |
process.exit(0); |
let mongooseConnected = false; | |
let redisConnected = false; | |
function tryToStartTheServer() { | |
if (mongooseConnected && redisConnected) { | |
console.log("mongoose and redis are connected. LET'S GO!"); | |
app.emit('ready'); | |
} | |
} |
const redisOptions = { host: env.REDIS_HOST, port: env.REDIS_PORT }; | |
if (env.NODE_ENV === 'production') { | |
redisOptions['password'] = env.REDIS_PASSWORD; | |
} | |
const redisClient = redis.createClient(redisOptions); | |
const redisEvents = [ | |
'ready', | |
'connect', | |
'end', | |
'error', |
let numberOfMongooseRetries = 1; | |
const THIRTY_SECONDS = 30000; | |
const MAX_DELAY_TO_RECONNECT = THIRTY_SECONDS; | |
async function connectToMongoose() { | |
console.log(`attempt ${numberOfMongooseRetries} to connect to mongo`); | |
try { | |
await mongoose.connect(env.MONGO_DB_CONNECTION_STRING, { useNewUrlParser: true }) | |
} | |
catch (err) { | |
// Note: this is where you would send errors to your error tracker |
function ensure(keys) { | |
const out = {}; | |
keys.forEach(key => { | |
if (!process.env[key]) { | |
throw new Error(`Missing environment variable ${key}`); | |
} | |
out[key] = process.env[key]; | |
}); | |
return out; | |
}; |
const mongooseEvents = [ | |
'close', | |
'connected', | |
'disconnected', | |
'disconnecting', | |
'error', | |
'fullsetup', | |
'all', | |
'reconnected', | |
'reconnectFailed', |
const express = require("express") | |
const http = require("http") | |
const redis = require("redis") | |
const mongoose = require('mongoose'); | |
const app = express(); | |
server = http.createServer(app); |
I hereby claim:
To claim this, I am signing this object: