Port of the Online Judge in Python
Initially the user chooses a language in the code editor and starts to write the answer based on the coding question. When the user submits the answer, the answer passes to the server. In the server a task id is being created in the PostgreSQL and the job is being sent to the RabbitMQ/Redis message queue. Then celery picks up the job and executes it in a sandbox environment which is developed using C. This helps to increase security and prevents malicious code injection attacks on the platform. When the job finishes execution the result is sent to the frontend using long poling. In this way the system verifies the users code, evaluate it and generates it ranking based on scores from other peers.
You can check out the code executor part of the project here.
https://docs.celeryproject.org/en/stable/getting-started/next-steps.html#next-steps
https://blog.logrocket.com/setting-up-a-remote-postgres-database-server-on-ubuntu-18-04/
This project uses PEP8 code style, please make sure to follow. Yapf is our preffered formatting tool. If you are using VSCode add the following in your settings.json
"python.formatting.provider": "yapf",
"python.formatting.yapfArgs": ["--style={based_on_style: pep8, indent_width: 4, column_limit: 120}"],
"python.linting.enabled": true
This project uses RabbitMQ as the primary option for implementing the message broker service. To set it up you need to have Docker on your system:
Instructions to set up Docker are here
To pull Rabbit mq, run sudo docker pull rabbitmq
in the terminal.
We use the Management plugin version of RabbitMQ, so to do that run:
sudo docker run -d -p 15672:15672 -p 5672:5672 -e RABBITMQ_DEFAULT_USER={{ your_custom_user }} -e RABBITMQ_DEFAULT_PASS={{ your_custom_password }} rabbitmq:3-management
Check the management console at http://host-ip:15672/
to see if the broker server is running fine.
This will generate a broker-url of the format amqp://{user}:{password}@{your_ip}:5672/
. Add this as the CELERY_BROKER_URL
in the .env
file for the project as well as the executors.
For the code execution part to function properly, you need to install a broker. Steps to install redis are as follows:
sudo apt install redis-server
sudo nano /etc/redis/redis.conf
- Inside the file find the
supervised
directive and change it tosystemd
. It should be set tono
by default.
...
supervised systemd
...
sudo systemctl restart redis.service
- Add
redis://localhost:6379
in theCELERY_BROKER_URL
part of the.env
file you have in your locally cloned repository.
To check if redis is working or not:
- Type in
redis-cli
- Type
ping
- If it returns
PONG
, then your redis-broker server is running fine.
https://linuxize.com/post/how-to-install-and-configure-redis-on-ubuntu-18-04/
https://www.w3resource.com/redis/redis-auth-password.php
To add Language models after running SQL migrations run
python manage.py loaddata --app interface language_model.json