Skip to content

Commit 8e172b2

Browse files
committed
Store the output of the script in the database
1 parent 549adad commit 8e172b2

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

webapp/src/Controller/API/JudgehostController.php

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use App\Entity\DebugPackage;
99
use App\Entity\Executable;
1010
use App\Entity\ExecutableFile;
11+
use App\Entity\GenericTask;
12+
use App\Entity\GenericTaskOutput;
1113
use App\Entity\InternalError;
1214
use App\Entity\Judgehost;
1315
use App\Entity\JudgeTask;
@@ -553,6 +555,63 @@ public function addDebugInfo(
553555
$this->em->flush();
554556
}
555557

558+
/**
559+
* Add generic task output.
560+
*/
561+
#[IsGranted('ROLE_JUDGEHOST')]
562+
#[Rest\Post('/add-generic-task/{hostname}/{judgeTaskId<\d+>}')]
563+
#[OA\Response(response: 200, description: 'When the task output has been added')]
564+
public function addGenericTaskOutput(
565+
Request $request,
566+
#[OA\PathParameter(description: 'The hostname of the judgehost that wants to add the task output')]
567+
string $hostname,
568+
#[OA\PathParameter(description: 'The ID of the judgetask to add', schema: new OA\Schema(type: 'integer'))]
569+
int $judgeTaskId
570+
): void {
571+
$judgeTask = $this->em->getRepository(JudgeTask::class)->find($judgeTaskId);
572+
if ($judgeTask === null) {
573+
throw new BadRequestHttpException(
574+
'Inconsistent data, no judgetask known with judgetaskid = ' . $judgeTaskId . '.');
575+
}
576+
577+
$required = ['generic_task'];
578+
foreach ($required as $argument) {
579+
if (!$request->request->has($argument)) {
580+
throw new BadRequestHttpException(
581+
sprintf("Argument '%s' is mandatory", $argument));
582+
}
583+
}
584+
585+
$judgehost = $this->em->getRepository(Judgehost::class)->findOneBy(['hostname' => $hostname]);
586+
if (!$judgehost) {
587+
throw new BadRequestHttpException("Who are you and why are you sending us any data?");
588+
}
589+
590+
$genericTask = $judgeTask->getGenericTasks();
591+
if (count($genericTask) === 0) {
592+
$genericTask = new GenericTask();
593+
$genericTask
594+
->setJudgeTask($judgeTask)
595+
->setStarttime($judgeTask->getStarttime())
596+
->setEndtime(Utils::now());
597+
$genericTaskOutput = new GenericTaskOutput();
598+
$genericTaskOutput->setGenericTask($genericTask);
599+
$genericTask->setOutput($genericTaskOutput);
600+
$this->em->persist($genericTask);
601+
$this->em->persist($genericTaskOutput);
602+
} elseif (count($genercTasks) !== 1) {
603+
throw new BadRequestHttpException("There should be only one generic task for this judgetask.");
604+
} else {
605+
$genericTask = $genericTask->first();
606+
}
607+
608+
$genericTask->setEndtime(Utils::now());
609+
$outputTask = base64_decode($request->request->get('generic_task'));
610+
$genericTaskOutput = $genericTask->getOutput();
611+
$genericTaskOutput->setOutputTask($outputTask);
612+
$this->em->flush();
613+
}
614+
556615
/**
557616
* Add one JudgingRun. When relevant, finalize the judging.
558617
* @throws DBALException
@@ -1238,7 +1297,7 @@ public function getFilesAction(
12381297
return match ($type) {
12391298
'source' => $this->getSourceFiles($id),
12401299
'testcase' => $this->getTestcaseFiles($id),
1241-
'compare', 'compile', 'debug', 'run' => $this->getExecutableFiles($id),
1300+
'compare', 'compile', 'debug', 'run', 'generic_task' => $this->getExecutableFiles($id),
12421301
default => throw new BadRequestHttpException('Unknown type requested.'),
12431302
};
12441303
}

webapp/src/Entity/GenericTask.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function setOutput(GenericTaskOutput $output): GenericTask
155155
{
156156
$this->output->clear();
157157
$this->output->add($output);
158-
$output->setRun($this);
158+
$output->setGenericTask($this);
159159

160160
return $this;
161161
}

webapp/src/Entity/JudgeTask.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ public function getSubmitid(): ?int
161161
#[Serializer\Exclude]
162162
private Collection $judging_runs;
163163

164+
/**
165+
* @var Collection<int, GenericTask>
166+
*/
167+
#[ORM\OneToMany(mappedBy: 'judgetask', targetEntity: GenericTask::class)]
168+
#[Serializer\Exclude]
169+
private Collection $generic_tasks;
170+
164171
#[ORM\ManyToOne(inversedBy: 'judgeTasks')]
165172
#[ORM\JoinColumn(name: 'versionid', referencedColumnName: 'versionid', onDelete: 'SET NULL')]
166173
#[Serializer\Exclude]

0 commit comments

Comments
 (0)