Source code for oioioi.evalmgr.models

import json

from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from oioioi.base.fields import EnumField, EnumRegistry
from oioioi.contests.models import Submission

[docs]job_states = EnumRegistry()
job_states.register('QUEUED', _("Queued")) job_states.register('PROGRESS', _("In progress")) job_states.register('CANCELLED', _("Cancelled")) job_states.register('WAITING', _("Waiting"))
[docs]class QueuedJob(models.Model):
[docs] job_id = models.CharField(max_length=50, primary_key=True)
[docs] state = EnumField(job_states, default='QUEUED')
[docs] creation_date = models.DateTimeField(
# Optional information about queued jobs.
[docs] submission = models.ForeignKey(Submission, null=True, on_delete=models.CASCADE)
[docs] celery_task_id = models.CharField(max_length=50, unique=True, null=True, blank=True)
[docs] class Meta(object):
[docs] verbose_name = _("Queued job")
[docs] verbose_name_plural = _("Queued jobs")
[docs] ordering = ['pk']
[docs]class SavedEnviron(models.Model): # A queued_job field can't be a primary key for this model, as it would # cause evalmgr to 'resume' job with results from previous asynchronous # call.
[docs] queued_job = models.OneToOneField(QueuedJob, on_delete=models.CASCADE)
[docs] environ = models.TextField(help_text=_("JSON-encoded evaluation environ"))
[docs] save_time = models.DateTimeField( auto_now=True, help_text=_("Time and date when the environ was saved") )
[docs] def load_environ(self): return json.loads(self.environ)
[docs] def save_environ(cls, environ): return cls.objects.create( queued_job=QueuedJob.objects.get(job_id=environ['job_id']), environ=json.dumps(environ), )