mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-19 09:51:37 +00:00
Start installing servers quicker (#454)
This commit is contained in:
parent
6966f06b1a
commit
ea396786e4
@ -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
|
||||
|
@ -60,7 +60,7 @@ public function setLog(?ServerLog $log): self
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
* @throws SSHConnectionError
|
||||
*/
|
||||
public function connect(bool $sftp = false): void
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user