Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

added sleep env variable for db connect timeout #351

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"host": "localhost",
"port": "PORT",
"public": "../public/",
"serverSelectionTimeout": "SERVER_SELECTION_TIMEOUT",
"paginate": {
"default": 10,
"max": 50
Expand Down
11 changes: 10 additions & 1 deletion api/src/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ export default function (app: Application) {
const settings = app.get("mongodb");
const connection = `mongodb://${settings.user}:${settings.password}@${settings.host}:${settings.port}/${settings.db}`;
const database = connection.substr(connection.lastIndexOf("/") + 1);
let serverSelectionTimeout = app.get("serverSelectionTimeout");
if(!serverSelectionTimeout){
serverSelectionTimeout = 30
}
const mongoClient = MongoClient.connect(connection, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then((client) => client.db(database));
serverSelectionTimeoutMS: serverSelectionTimeout*1000
}).then((client) => client.db(database))
.catch((error) =>{
console.error("Database connection failed", error);
process.exit(1);
});

app.set("mongoClient", mongoClient);
}
1 change: 1 addition & 0 deletions docker/api/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"host": "localhost",
"port": "PORT",
"public": "../public/",
"serverSelectionTimeout": "SERVER_SELECTION_TIMEOUT",
"paginate": {
"default": 10,
"max": 50
Expand Down
2 changes: 2 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
DB_USER: ${MONGODB_USER}
DB_PASSWORD: ${MONGODB_PASSWORD}
DB_PORT: ${MONGODB_PORT}
SERVER_SELECTION_TIMEOUT: ${SERVER_SELECTION_TIMEOUT}
SMTP_HOST: ${SMTP_HOST}
SMTP_PORT: ${SMTP_PORT}
ADMIN_EMAIL: ${ADMIN_EMAIL}
Expand Down Expand Up @@ -42,6 +43,7 @@ services:
DB_USER: ${MONGODB_USER}
DB_PASSWORD: ${MONGODB_PASSWORD}
DB_PORT: ${MONGODB_PORT}
SERVER_SELECTION_TIMEOUT: ${SERVER_SELECTION_TIMEOUT}
SMTP_HOST: ${SMTP_HOST}
SMTP_PORT: ${SMTP_PORT}
ADMIN_EMAIL: ${ADMIN_EMAIL}
Expand Down
1 change: 1 addition & 0 deletions docker/manage
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ configureEnvironment() {
export API_PORT=5000
export AGENT_ADMIN_URL=${AGENT_ADMIN_URL:-http://agent:$AGENT_ADMIN_PORT}
export DB_SERVICE="db"
export SERVER_SELECTION_TIMEOUT=${SERVER_SELECTION_TIMEOUT:-30}
export SMTP_HOST=${SMTP_HOST:-maildev}
export SMTP_PORT=${SMTP_PORT:-25}
export ADMIN_EMAIL=${ADMIN_EMAIL:-"noreply@example.com"}
Expand Down