PremierLangage / platon-server

Backend project of PLaTon platform.
Other
1 stars 0 forks source link

django_sandbox apps #9

Closed qcoumes closed 4 years ago

qcoumes commented 4 years ago

This module allows interaction with multiple Sandbox servers.

Sandbox

Multiple Sandbox can be defined, each Sandbox must have a unique name and url, they also have a boolean sandbox.enabled, allowing to enable/disable Sandbox on command.

SandboxSpecs, ContainerSpecs and Usage

When a new Sandbox is created, two django_celery_beat.models.PeriodicTask are created :

  1. One to run Sandbox.poll_specifications() every settings.SANDBOX_POLL_SPECS_EVERY
  2. The other to run Sandbox.poll_usage() every settings.SANDBOX_POLL_USAGE_EVERY

The tasks will only run if Celery is running (through ./bin/celery.sh). Celery also need Redis, which can be easily ran inside a container with ./bin/redis_docker.sh (Redis will also be needed for websocket).

Specifications are stored inside two models :

  1. SandboxSpecs, accessed through sandbox.server_specs, which contains information about the hosting machine.
  2. ContainerSpecs, accessed through sandbox.container_specs, which contains information about a container on the sandbox.

Usages are stored in the model Usage, a sandbox can list all its usage (sorted by date) with sandbox.usages.all().

Request, Response and CommandResult

Sandbox has an execute() method that sends an execute/ request to the corresponding server. This method create a new Request instance, containing information about the execution such as user, date, config and status.

A Response contains all the general information about the execution, and a list of CommandResult, which contain details for each command.

See django_sandbox.models for more information.