How to make NestJS start even if one (or more) modules failed - nestjs

I have a NestJS app that connects to many services - RabbitMQ, Redis and TypeORM - postgres DB.
I want to make it so that even if, for example, the database connection can't be made, the app can still start and won't just crash...
Is that even possible?

Related

Connection Pooling in typeorm with postgressql

I've gone through enough articles and typeorm official documentation on setting up connection pooling with typeorm and postgressql but couldn't find a solution.
All the articles, I've seen so far explains about adding the max/Poolsize attribute in orm configuration or connection pooling but this is not setting up a pool of idle connections in the database.
When I verify pg_stat_activity table after the application bootstraps, I could not see any idle connections in the DB but when a request is sent to the application I could see an active connection to the DB
The max/poolSize attribute defined under the extras in the orm configuration merely acts as the max number of connections that can be opened from the application to the db concurrently.
What I'm expecting is that during the bootstrap, the application opens a predefined number of connections with the database and keep it in idle state. When a request comes into the application one of the idle connection is picked up and the request is served.
Can anyone provide your insights on how to have this configuration defined with typeorm and postgresql?
TypeORM uses node-postgres which has built in pg-pool and doesn't have that kind of option, as far as I can tell. It supports a max, and as your app needs more connections it will create them, so if you want to pre-warm it, or maybe load/stress test it, and see those additional connections you'll need to write some code that kicks off a bunch of async queries/inserts.
I think I understand what you're looking for as I used to do enterprise Java, and connection pools in things like glassfish and jboss have more options where you can keep hot unused connections in the pool. There are no such options in TypeORM/node-postgres though.

Micro Services Architecture if using Sequelize as an ORM

I'm developing a chat application that consists of several micro-services or nodes. And to handle database I use Sequelize ORM.
However, I've two separate nodes one for handling socket messages and another one is a general API server. Both of them have to use Sequelize.
How can I use Sequelize in both? I don't want the same code to copy paste in two different services.
What we have done in our project, is to connect socket server and API server. Thus API server is a special socket client for the socket server. Thus if we need to do some db query we pass data to-fro between them.

sails.js connection failure fallback

My Sails application has different models, most of them connected to MongoDb via sails-mongo adapter and few of them connected to Redis via sails-redis (the "real-time" scenario part of the models, such as Notifications, which are light and may have short lifespan).
However, I would like my application to start even if the Redis connection is down, and have limited functionality for the users. However if I run the application with redis closed it doesn't start as it expects all connections to work.
Can this be somehow solved without fragmenting the application into multiple services? Or if not then can a fallback connection be defined for the models in question?

Sails mongodb missing connection handling

Very simple and stupid question I came up with today when was playing around with sails and mongo db (adapter of the waterline odm). I just shut down the mongo while my sails server still has been running and saw nothing, neither in logs of sails or in the browser. How I could handle such situation?
If sails.js attempts a connection to the DB you will most certainly get a message in your console if the Mongo server is shut down, but if no request is made that requires a DB connection, then you will not see any error because no error as of yet exists.
It sounds like you might require a process that will monitor your DB and check to make sure it is still running? There are Sail.js options where you could create a CRON job to check the connection. Or you could use other application monitoring services like New Relic to monitor your DB.

node-orm-transaction: is it possible to perform transactions in one mysql connection for all clients?

Currently i connect to the db only once, when i start my node application, just after that i load all my models and after that my app is ready to handle any requests via socket.io rpc.
I need to achieve the logic - that if client performs complex request, and if at least one operation failed in chain - for example - all sql requests were done successfully, but email with new password was not sent - rollback everything and show error.
I'm asking, because I remember - in php for example all processes have different connections to db, that's why all transations are independent and can't cross, but for node it's just one process with async requests, that in theory can cross. It's just my first app on node.js.
Is it possible to make with 1 mysql connection for all clients, or i need to connect to mysql, retrieve all models from remote file in each request in socket.io?
I would not recommend doing everything from a single connection. It's a common pattern in Node.js to connect, query, disconnect for each incoming request. If you use request pooling this should be fast enough for most use cases.

Resources