Avoid memory leaks, use as little RAM as possible, keep your code clean. For example, Example: I created a script that has nothing but an infinite loop with time.sleep()
. Together with the tmux
session (discussed below), it occupies 12.2 megabytes of RAM, although this script can simply be turned off during inactivity, especially if the time interval is large enough. For example, more than 10 minutes.
For clarity, it is important to use the same namings for the virtual environment, project root directory, gitlab/github project name, tmux session, database name, and so on.
Don’t store data locally, use a database server instead. Exceptions: configs and cache. In other cases, I recommend cloud-based MongoDB Atlas.
Always keep in mind that one day you may move from one server to another. Or even worse - suddenly lose access to the server or accidentally delete something. This is why you should have up-to-date versions of the code stored on gitlab/github. This is why it is worth separating your project server and database server.
Your project should be easy to deploy with just a couple of commands. For example, start.sh
.
Is worth determining which category the service will belong.
All python services should be placed in separate miniconda environments to avoid dependency conflicts. For example, the ta-lib library requires Python version = 3.5 to work, and aiogram >= 3.6 to work. Different projects require different versions of python.
Typical project structure:
main.py
- main executable file, usually one is enough. If more is required, it is better to use command line arguments.config.py
- separate from main.py
.environment.yml
- generated using miniconda.start.sh
- this script creates a tmux session for the project. A universal example that I use:
|
|
Each process should be placed in a separate tmux shell. This will allow you to detach from the process and return to the terminal. Tmux cheat sheet:
Linux has a built-in scheduler cron
. Read about cron in my post.
Typical project structure:
main.py
- main executable file, usually one is enough. If more is required, it is better to use command line arguments.config.py
- separate from main.py
.environment.yml
- generated using miniconda.start.sh
- this script creates a tmux session for the project. A universal example that I use:
|
|