Start installing servers quicker (#454)

This commit is contained in:
Saeed Vaziry 2025-01-31 00:20:41 +01:00 committed by GitHub
parent 6966f06b1a
commit ea396786e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 27 deletions

View File

@ -6,6 +6,7 @@
use App\Enums\ServerProvider;
use App\Enums\ServerStatus;
use App\Enums\ServerType;
use App\Exceptions\SSHConnectionError;
use App\Facades\Notifier;
use App\Models\Project;
use App\Models\Server;
@ -15,7 +16,6 @@
use App\ValidationRules\RestrictedIPAddressesRule;
use Exception;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
@ -81,18 +81,25 @@ public function create(User $creator, Project $project, array $input): Server
private function install(Server $server): void
{
$bus = Bus::chain([
function () use ($server) {
if (! $server->provider()->isRunning()) {
sleep(2);
dispatch(function () use ($server) {
$maxWait = 180;
while ($maxWait > 0) {
sleep(10);
$maxWait -= 10;
try {
$server->ssh()->connect();
break;
} catch (SSHConnectionError) {
// ignore
}
}
$server->type()->install();
$server->update([
'status' => ServerStatus::READY,
]);
Notifier::send($server, new ServerInstallationSucceed($server));
},
])->catch(function (Throwable $e) use ($server) {
})
->catch(function (Throwable $e) use ($server) {
$server->update([
'status' => ServerStatus::INSTALLATION_FAILED,
]);
@ -100,15 +107,8 @@ function () use ($server) {
Log::error('server-installation-error', [
'error' => (string) $e,
]);
});
if ($server->provider != ServerProvider::CUSTOM) {
$server->progress_step = 'waiting-for-provider';
$server->save();
$bus->delay(now()->addMinutes(3));
}
$bus->onConnection('ssh')->dispatch();
})
->onConnection('ssh');
}
public static function rules(Project $project, array $input): array

View File

@ -60,7 +60,7 @@ public function setLog(?ServerLog $log): self
}
/**
* @throws Throwable
* @throws SSHConnectionError
*/
public function connect(bool $sftp = false): void
{