vito/app/Jobs/Server/CheckConnection.php
Saeed Vaziry e997d0deea
WIP notifications and other refactors (#88)
* WIP notifications and other refactors
- refactor notification channels
- send notifications on events related to the servers and sites
- delete server log files on server deletion
- add telegram notification channel
- add new icons
- cache configs and icons on installation and updates
- new navbar for dark mode and settings

* discord channel

* build assets

* pint
2024-01-07 09:54:08 +01:00

52 lines
1.1 KiB
PHP

<?php
namespace App\Jobs\Server;
use App\Events\Broadcast;
use App\Facades\Notifier;
use App\Jobs\Job;
use App\Models\Server;
use App\Notifications\ServerDisconnected;
use Throwable;
class CheckConnection extends Job
{
protected Server $server;
public function __construct(Server $server)
{
$this->server = $server;
}
/**
* @throws Throwable
*/
public function handle(): void
{
$status = $this->server->status;
$this->server->ssh()->connect();
$this->server->refresh();
if ($status == 'disconnected') {
$this->server->status = 'ready';
$this->server->save();
}
event(
new Broadcast('server-status-finished', [
'server' => $this->server,
])
);
}
public function failed(): void
{
$this->server->status = 'disconnected';
$this->server->save();
Notifier::send($this->server, new ServerDisconnected($this->server));
event(
new Broadcast('server-status-failed', [
'server' => $this->server,
])
);
}
}