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