This commit is contained in:
ITQ
2025-03-03 11:49:38 +03:00
parent 91e1c2842c
commit a98b63a781
+21 -10
View File
@@ -2,27 +2,38 @@ import httpx
from celery import shared_task from celery import shared_task
from django.conf import settings from django.conf import settings
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
import hashlib
from apps.task.models import CompetitionTaskSubmission
@shared_task(bind=True, max_retries=3) @shared_task(bind=True, max_retries=3)
def analyze_data_task(self, submission_id): def analyze_data_task(self, submission_id):
from .models import CompetitionTaskSubmission
submission = CompetitionTaskSubmission.objects.get(id=submission_id) submission = CompetitionTaskSubmission.objects.get(id=submission_id)
try: try:
code = submission.content.read().decode() code_url = (
f"{settings.MINIO_DEFAULT_CUSTOM_ENDPOINT_URL}{submission.path}"
)
files = [ files = [
(f.name, f.file.open("rb")) {
for f in submission.task.attachments.filter(public=True) "url": f"{settings.MINIO_DEFAULT_CUSTOM_ENDPOINT_URL}{attachment.path}",
"bind_path": attachment.bind_at,
}
for attachment in submission.task.attachments.filter(
bind_path__isnull=False
)
] ]
response = httpx.post( response = httpx.post(
f"{settings.CHECKER_API_ENDPOINT}/execute", f"{settings.CHECKER_API_ENDPOINT}/execute",
files=[("files", (f.name, f)) for f in files] json={
+ [ "files": files,
("code", code), "code_url": code_url,
("expected_hash", submission.task.correct_answer_hash), "answer_file_path": submission.task.answer_file_path,
], "expected_hash": hashlib.sha256(
submission.task.correct_answer_file.read().encode()
).hexdigest(),
},
timeout=30, timeout=30,
) )
response.raise_for_status() response.raise_for_status()