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
8 changes: 2 additions & 6 deletions app/Http/Controllers/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Rules\ProjectNameRule;
use App\Utils\AuthTokenUtil;
use App\Utils\SubmissionUtils;
use App\Utils\SystemUtils;
use App\Utils\UnparsedSubmissionProcessor;
use CDash\Model\Build;
use CDash\Model\Project;
Expand Down Expand Up @@ -129,12 +130,7 @@ private function submitProcess(): Response
}

// Check if we can connect to the database before proceeding any further.
try {
DB::connection()->getPdo();
if (app()->isDownForMaintenance()) {
throw new Exception();
}
} catch (Exception) {
if (!SystemUtils::isDatabaseOnline()) {
// Write a marker file so we know to process these files when the DB comes back up.
if (!Storage::exists('DB_WAS_DOWN')) {
Storage::put('DB_WAS_DOWN', '');
Expand Down
26 changes: 26 additions & 0 deletions app/Utils/SystemUtils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace App\Utils;

use Exception;
use Illuminate\Support\Facades\DB;

class SystemUtils
{
public static function isDatabaseOnline(): bool
{
// We consider the database to be offline if migrations are running.
if (app()->isDownForMaintenance()) {
return false;
}

try {
DB::connection()->getPdo();
return true;
} catch (Exception) {
return false;
}
}
}
15 changes: 2 additions & 13 deletions app/Utils/UnparsedSubmissionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function postSubmit(): JsonResponse
// Thus function will throw an exception if invalid data provided
$this->parseBuildMetadata();

if ($this->checkDatabaseConnection() && !app()->isDownForMaintenance()) {
if (SystemUtils::isDatabaseOnline()) {
return $this->initializeBuild();
}

Expand Down Expand Up @@ -213,7 +213,7 @@ public function putSubmitFile(): JsonResponse
$this->parseDataFileParameters();
$ext = pathinfo($this->backupfilename, PATHINFO_EXTENSION);

$db_up = $this->checkDatabaseConnection() && !app()->isDownForMaintenance();
$db_up = SystemUtils::isDatabaseOnline();
if ($db_up) {
if (!is_numeric($this->buildid) || $this->buildid < 1) {
abort(Response::HTTP_NOT_FOUND, 'Build not found');
Expand Down Expand Up @@ -370,17 +370,6 @@ public function parseDataFileParameters(): void
$this->getAuthTokenHash();
}

/** Check if CDash's database is down. */
private function checkDatabaseConnection(): bool
{
try {
DB::connection()->getPdo();
return true;
} catch (Exception) {
return false;
}
}

/** Write build metadata to disk in JSON format. */
private function serializeBuildMetadata(string $uuid): void
{
Expand Down