So we successfully connected with the database, but still we have that issue that the jungle doesn't
connect directly with the database to solve that problem.
We need to order custom commands.
So in the cover up, I'll create a new directory management.
And here I will create a python file, underscore, underscore, in it, underscore, underscore, we
do not need to write anything here, so we will create another directory commands and copy these pasted
here since it will be the same empty file.
And now let's create the command that we need.
So we'll create a python file file called Wait for DB.
So this will be a command that we need to wait for the database.
So let's create that command subclass command in need.
This needs to extend to the base command.
So the base command, we need to import it from Jungle Core Management Base Command, so.
This is a function all call it Hendel here and this this has arguments and options.
And what I will do right now is first I will write a message as to the out.
Right, waiting for the database.
So, all right, this message in the.
The connection will be equal to none in the other wide loop here, while not connected.
What do we want to do?
I will try except here.
We will try to connect with a database of the connection will be equal to Connexions.
Default, so we need to import the connections from got deep connections, so we'll try to get the connection
and once we get it, we'll break of this wall.
And if the connection doesn't, uh, is not successful, we will get the accept part.
So this is an operation.
Or let's import it, so this is from, uh.
So it's imported from jungle DBI, utils import operational error, so we will encounter this problem,
let's import also by time and we will write here a message.
Database and unavailable.
Wading.
For one second
and will call time sleep one here, so this is a while loop, if the connection is not available, we
will wait one second until we are connected with the database.
And in the end, I will write a message.
So if we go here, we will write database available.
Legalese, so we can add also style here, so self styled.
Fuchs's.
So this is the command that we need to run to run this command.
We need to call the name wait for Debbie so the command will be able go to the doctor file by on.
Manage that by wait for Debbie, and then we will run the server, so first we will wait for the connection.
If this is successful, then we'll run the server.
So this is how it will work.
And also this is how we create commands.
We are the management folder commands, and the name of the file will be the actual command, so.
All stop the doctor, so.
To stop, we are stopping here, the bacon, but if we want to stop also the database, we run the compost
down and we stopped also a database.
Now, if we want to run this new command here, it won't work.
If we're undercover, compose up.
We probably will have the same problem or not.
Do we have the message waiting for the database?
Not sure why it's not it's working right now, let's run it again.
And we have the problem, yes, so why do we have the problem, even though we have the command here?
Because the Dogra file, we are not building it.
So we are stopping and running again, the same container, but we are not running this command.
To run that command.
We have to run Dakkar, compose up, build.
So this will rebuild the container again, and this time it will run this command.
So this will rebuild both the containers.
And we have here database is available, and why do we have, again, another problem?
Not to build the recomposed up.
So I found the problem is I wrote the success wrong in the command, so this should be should have another
earthier.
So this is a pretty silly mistake.
We need to build it again.
And right now is running successfully if we underground polls up every time now, we don't have any
more problems.
So this is how we wait for the database.