Skip to content

Commit 240a631

Browse files
committed
Properly record start and end times of judging runs.
The previously recorded end time was the time when we processed the judging run result server wise which is done asynchronously. Progress towards: #1164
1 parent d9c773c commit 240a631

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

judge/judgedaemon.main.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,7 @@ function compile(
13251325
function judge(array $judgeTask): bool
13261326
{
13271327
global $EXITCODES, $myhost, $options, $workdirpath, $exitsignalled, $gracefulexitsignalled, $endpointID;
1328+
$startTime = microtime(true);
13281329

13291330
$compile_config = dj_json_decode($judgeTask['compile_config']);
13301331
$run_config = dj_json_decode($judgeTask['run_config']);
@@ -1509,6 +1510,8 @@ function judge(array $judgeTask): bool
15091510

15101511
$new_judging_run = [
15111512
'runresult' => urlencode($result),
1513+
'start_time' => urlencode((string)$startTime),
1514+
'end_time' => urlencode((string)microtime(true)),
15121515
'runtime' => urlencode((string)$runtime),
15131516
'output_run' => rest_encode_file($passdir . '/program.out', $output_storage_limit),
15141517
'output_error' => rest_encode_file($passdir . '/program.err', $output_storage_limit),
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20250831173317 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return '';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('ALTER TABLE judging_run ADD start_time NUMERIC(32, 9) UNSIGNED DEFAULT NULL COMMENT \'Time run judging started\'');
24+
}
25+
26+
public function down(Schema $schema): void
27+
{
28+
// this down() migration is auto-generated, please modify it to your needs
29+
$this->addSql('ALTER TABLE judging_run DROP start_time');
30+
}
31+
32+
public function isTransactional(): bool
33+
{
34+
return false;
35+
}
36+
}

webapp/src/Controller/API/JudgehostController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ public function addJudgingRunAction(
644644
}
645645

646646
$runResult = $request->request->get('runresult');
647+
$startTime = $request->request->get('start_time');
648+
$endTime = $request->request->get('end_time');
647649
$runTime = $request->request->get('runtime');
648650
$outputRun = $request->request->get('output_run');
649651
$outputDiff = $request->request->get('output_diff');
@@ -659,7 +661,7 @@ public function addJudgingRunAction(
659661
throw new BadRequestHttpException("Who are you and why are you sending us any data?");
660662
}
661663

662-
$hasFinalResult = $this->addSingleJudgingRun($judgeTaskId, $hostname, $runResult, $runTime,
664+
$hasFinalResult = $this->addSingleJudgingRun($judgeTaskId, $hostname, $runResult, $runTime, $startTime, $endTime,
663665
$outputSystem, $outputError, $outputDiff, $outputRun, $teamMessage, $metadata, $testcasedir, $compareMeta);
664666
$judgehost = $this->em->getRepository(Judgehost::class)->findOneBy(['hostname' => $hostname]);
665667
$judgehost->setPolltime(Utils::now());
@@ -924,6 +926,8 @@ private function addSingleJudgingRun(
924926
string $hostname,
925927
string $runResult,
926928
string $runTime,
929+
string $startTime,
930+
string $endTime,
927931
string $outputSystem,
928932
string $outputError,
929933
string $outputDiff,
@@ -945,6 +949,8 @@ private function addSingleJudgingRun(
945949
$this->em->wrapInTransaction(function () use (
946950
$judgeTaskId,
947951
$runTime,
952+
$startTime,
953+
$endTime,
948954
$runResult,
949955
$outputSystem,
950956
$outputError,
@@ -966,7 +972,8 @@ private function addSingleJudgingRun(
966972
$judgingRun
967973
->setRunresult($runResult)
968974
->setRuntime((float)$runTime)
969-
->setEndtime(Utils::now())
975+
->setStarttime($startTime)
976+
->setEndtime($endTime)
970977
->setTestcasedir($testcasedir);
971978
$judgingRunOutput
972979
->setOutputRun(base64_decode($outputRun))

webapp/src/Entity/JudgingRun.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ class JudgingRun extends BaseApiEntity
6060
#[Serializer\Exclude]
6161
private string|float|null $endtime = null;
6262

63+
#[ORM\Column(
64+
type: 'decimal',
65+
precision: 32,
66+
scale: 9,
67+
nullable: true,
68+
options: ['comment' => 'Time run judging started', 'unsigned' => true]
69+
)]
70+
#[Serializer\Exclude]
71+
private string|float|null $startTime = null;
72+
6373
#[ORM\ManyToOne(inversedBy: 'runs')]
6474
#[ORM\JoinColumn(name: 'judgingid', referencedColumnName: 'judgingid', onDelete: 'CASCADE')]
6575
#[Serializer\Exclude]
@@ -157,6 +167,17 @@ public function setEndtime(string|float $endtime): JudgingRun
157167
return $this;
158168
}
159169

170+
public function setStarttime(string|float $startTime): JudgingRun
171+
{
172+
$this->startTime = $startTime;
173+
return $this;
174+
}
175+
176+
public function getStarttime(): string|float|null
177+
{
178+
return $this->startTime;
179+
}
180+
160181
public function getEndtime(): string|float|null
161182
{
162183
return $this->endtime;

0 commit comments

Comments
 (0)