Commit 7b8236a7 authored by Matej Dujava's avatar Matej Dujava
Browse files

Add variable delay between two submissions


Signed-off-by: default avatarMatej Dujava <mdujava@gmail.com>
parent 3d8676b8
Pipeline #31228 passed with stage
in 6 minutes and 28 seconds
......@@ -13,7 +13,7 @@ def get_project(factory: DataFactory, course: Course, num: int):
file_whitelist="main.cpp",
pre_submit_script="python for kontr pre",
post_submit_script="python for kontr post",
submission_scheduler_config="python for sub Q",
submission_scheduler_config="delay: 1",
submission_parameters="{\"type\":\"text\"}",
submissions_allowed_from=time.current_time(),
submissions_allowed_to=time.current_time() + timedelta(days=2),
......@@ -66,7 +66,7 @@ def init_dev_data(app: Flask, db: SQLAlchemy):
test_files_subdir='',
pre_submit_script="python for kontr pre",
post_submit_script="python for kontr post",
submission_scheduler_config="python for sub Q",
submission_scheduler_config="delay: 2",
submission_parameters="{\"type\":\"text\"}",
submissions_allowed_from=time.current_time() - timedelta(days=1),
submissions_allowed_to=time.current_time() + timedelta(days=10),
......@@ -82,7 +82,7 @@ def init_dev_data(app: Flask, db: SQLAlchemy):
test_files_subdir='',
pre_submit_script="python for kontr pre",
post_submit_script="python for kontr post",
submission_scheduler_config="python for sub Q",
submission_scheduler_config="delay: 3",
submission_parameters="{\"type\":\"text\"}",
submissions_allowed_from=time.current_time() - timedelta(days=1),
submissions_allowed_to=time.current_time() + timedelta(days=10),
......@@ -97,7 +97,7 @@ def init_dev_data(app: Flask, db: SQLAlchemy):
test_files_subdir='',
pre_submit_script="python for kontr pre",
post_submit_script="python for kontr post",
submission_scheduler_config="python for sub Q",
submission_scheduler_config="delay: 4",
submission_parameters="{\"type\":\"text\"}",
submissions_allowed_from=time.current_time() - timedelta(days=1),
submissions_allowed_to=time.current_time() - timedelta(minutes=1),
......
......@@ -3,6 +3,7 @@ Projects service
"""
import datetime
import logging
import yaml
from datetime import timedelta
from typing import List
......@@ -148,15 +149,38 @@ class ProjectService(GeneralService):
latest_time = latest_submission.created_at
now_time = datetime.datetime.utcnow()
diff_time = now_time - latest_time
delta = timedelta(minutes=30) # TODO this should be configurable @mdujava
submission_config = self.load_scheduler_config()
delta = submission_config['delay']
log.info(f"Submission for project {self.project.log_name} by user {user.log_name},"
f" time delta: {diff_time} < {delta} = {diff_time < delta} created")
if diff_time < delta:
log.debug(f"Submission for {self.project.log_name} by {user.log_name} "
f"rejected based on the time delta: {diff_time}")
raise errors.SubmissionDiffTimeError(self.project, diff_time, user=user)
raise errors.SubmissionDiffTimeError(self.project, (latest_time + delta) - now_time, user=user)
return True
def load_scheduler_config(self) -> dict():
submission_scheduler_config = {}
minutes = 30
try:
loaded_config = yaml.safe_load(self.project.config.submission_scheduler_config)
if 'delay' in loaded_config:
minutes = loaded_config['delay']
log.info(f"Delay for project {self.project.log_name}, reading from config: "
"{submission_scheduler_config['delay']}")
except yaml.YAMLError:
log.error(f"Project {self.project.log_name}, failed parsing delay from config: "
"{self.project.config.submission_scheduler_config}")
submission_scheduler_config['delay'] = datetime.timedelta(minutes=minutes)
return submission_scheduler_config
def get_latest_submission(self, user, ignore_cancel: bool = False) -> models.Submission:
query = queries.list_submissions_universal(user=user, project=self.project)
if ignore_cancel:
......@@ -183,5 +207,6 @@ class ProjectService(GeneralService):
if not latest_submission:
return time.current_time()
latest_time = latest_submission.created_at
delta = datetime.timedelta(minutes=30)
submission_config = self.load_scheduler_config()
delta = submission_config['delay']
return latest_time + delta
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment