Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions webapp/src/DataTransferObject/Shadowing/LanguageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

class LanguageEvent implements EventData
{
/**
* @param list<string>|null $extensions
*/
public function __construct(
public readonly string $id,
public readonly ?array $extensions = null,
) {}
}
50 changes: 31 additions & 19 deletions webapp/src/Service/ExternalContestSourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,10 @@ protected function importFromCcsApi(array $eventsToSkip, ?callable $progressRepo
};

while (true) {
// A timeout of 0.0 means we get chunks immediately and the user
// can cancel at any time.
try {
$receivedData = false;
foreach ($this->httpClient->stream($response, 0.0) as $chunk) {
// Get a timeout chunk after 1 second so we don't hang indefinitely.
foreach ($this->httpClient->stream($response, 1.0) as $chunk) {
// We first need to check for timeouts, as we can not call
// ->isLast() or ->getContent() on them.
if (!$chunk->isTimeout()) {
Expand Down Expand Up @@ -833,6 +832,10 @@ protected function validateLanguage(Event $event, EventData $data): void
]);
} else {
$this->removeWarning($event->type, $data->id, ExternalSourceWarning::TYPE_DATA_MISMATCH);

$toCheck = ['extensions' => $data->extensions];

$this->compareOrCreateValues($event, $data->id, $language, $toCheck);
}
}

Expand Down Expand Up @@ -1432,6 +1435,10 @@ protected function importSubmission(Event $event, EventData $data): void
$zipUrl = $data->files[0]->href;
if (preg_match('/^https?:\/\//', $zipUrl) === 0) {
// Relative URL, prepend the base URL.
// If the base URL ends with a slash and the zip URL starts with one, remove the slash.
if (str_ends_with($this->basePath, '/') && str_starts_with($zipUrl, '/')) {
$zipUrl = substr($zipUrl, 1);
}
$zipUrl = ($this->basePath ?? '') . $zipUrl;
}

Expand Down Expand Up @@ -1461,26 +1468,31 @@ protected function importSubmission(Event $event, EventData $data): void
}

if ($submissionDownloadSucceeded) {
try {
$response = $this->httpClient->request('GET', $zipUrl);
$ziphandler = fopen($zipFile, 'w');
if ($response->getStatusCode() !== 200) {
// TODO: Retry a couple of times.
$tries = 1;
do {
try {
$response = $this->httpClient->request('GET', $zipUrl);
$ziphandler = fopen($zipFile, 'w');
if ($response->getStatusCode() !== 200) {
$this->addOrUpdateWarning($event, $data->id, ExternalSourceWarning::TYPE_SUBMISSION_ERROR, [
'message' => "Cannot download ZIP from $zipUrl after trying $tries times",
]);
$submissionDownloadSucceeded = false;
// Sleep a bit before retrying
sleep(3);
}
$tries++;
} catch (TransportExceptionInterface $e) {
$this->addOrUpdateWarning($event, $data->id, ExternalSourceWarning::TYPE_SUBMISSION_ERROR, [
'message' => 'Cannot download ZIP from ' . $zipUrl,
'message' => "Cannot download ZIP from $zipUrl after trying $tries times: " . $e->getMessage(),
]);
if (isset($ziphandler)) {
fclose($ziphandler);
}
unlink($zipFile);
$submissionDownloadSucceeded = false;
}
} catch (TransportExceptionInterface $e) {
$this->addOrUpdateWarning($event, $data->id, ExternalSourceWarning::TYPE_SUBMISSION_ERROR, [
'message' => 'Cannot download ZIP from ' . $zipUrl . ': ' . $e->getMessage(),
]);
if (isset($ziphandler)) {
fclose($ziphandler);
}
unlink($zipFile);
$submissionDownloadSucceeded = false;
}
} while ($tries <= 3 && !$submissionDownloadSucceeded);
}

if (isset($response, $ziphandler) && $submissionDownloadSucceeded) {
Expand Down
Loading