feat(sentinel): implement SentinelRestarted event and update Livewire components to handle server restart notifications
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Actions\Server;
|
namespace App\Actions\Server;
|
||||||
|
|
||||||
|
use App\Events\SentinelRestarted;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Lorisleiva\Actions\Concerns\AsAction;
|
use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
|
|
||||||
@@ -61,5 +62,8 @@ class StartSentinel
|
|||||||
$server->settings->is_sentinel_enabled = true;
|
$server->settings->is_sentinel_enabled = true;
|
||||||
$server->settings->save();
|
$server->settings->save();
|
||||||
$server->sentinelHeartbeat();
|
$server->sentinelHeartbeat();
|
||||||
|
|
||||||
|
// Dispatch event to notify UI components
|
||||||
|
SentinelRestarted::dispatch($server, $version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
app/Events/SentinelRestarted.php
Normal file
39
app/Events/SentinelRestarted.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||||
|
use Illuminate\Broadcasting\PrivateChannel;
|
||||||
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class SentinelRestarted implements ShouldBroadcast
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
|
public ?int $teamId = null;
|
||||||
|
|
||||||
|
public ?string $version = null;
|
||||||
|
|
||||||
|
public string $serverUuid;
|
||||||
|
|
||||||
|
public function __construct(Server $server, ?string $version = null)
|
||||||
|
{
|
||||||
|
$this->teamId = $server->team_id;
|
||||||
|
$this->serverUuid = $server->uuid;
|
||||||
|
$this->version = $version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function broadcastOn(): array
|
||||||
|
{
|
||||||
|
if (is_null($this->teamId)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
new PrivateChannel("team.{$this->teamId}"),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@@ -67,8 +67,11 @@ class Show extends Component
|
|||||||
|
|
||||||
public function getListeners()
|
public function getListeners()
|
||||||
{
|
{
|
||||||
|
$teamId = $this->server->team_id ?? auth()->user()->currentTeam()->id;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'refreshServerShow' => 'refresh',
|
'refreshServerShow' => 'refresh',
|
||||||
|
"echo-private:team.{$teamId},SentinelRestarted" => 'handleSentinelRestarted',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,6 +224,16 @@ class Show extends Component
|
|||||||
$this->syncData();
|
$this->syncData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleSentinelRestarted($event)
|
||||||
|
{
|
||||||
|
// Only refresh if the event is for this server
|
||||||
|
if (isset($event['serverUuid']) && $event['serverUuid'] === $this->server->uuid) {
|
||||||
|
$this->server->refresh();
|
||||||
|
$this->syncData();
|
||||||
|
$this->dispatch('success', 'Sentinel has been restarted successfully.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function validateServer($install = true)
|
public function validateServer($install = true)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -255,7 +268,7 @@ class Show extends Component
|
|||||||
try {
|
try {
|
||||||
$this->authorize('manageSentinel', $this->server);
|
$this->authorize('manageSentinel', $this->server);
|
||||||
$this->server->restartSentinel();
|
$this->server->restartSentinel();
|
||||||
$this->dispatch('success', 'Sentinel restarted.');
|
$this->dispatch('success', 'Restarting Sentinel.');
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
@@ -304,7 +317,7 @@ class Show extends Component
|
|||||||
try {
|
try {
|
||||||
$this->authorize('manageSentinel', $this->server);
|
$this->authorize('manageSentinel', $this->server);
|
||||||
$this->server->settings->generateSentinelToken();
|
$this->server->settings->generateSentinelToken();
|
||||||
$this->dispatch('success', 'Token regenerated & Sentinel restarted.');
|
$this->dispatch('success', 'Token regenerated. Restarting Sentinel.');
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Livewire\Source\Gitlab;
|
|
||||||
|
|
||||||
use Livewire\Component;
|
|
||||||
|
|
||||||
class Change extends Component
|
|
||||||
{
|
|
||||||
public function render()
|
|
||||||
{
|
|
||||||
return view('livewire.source.gitlab.change');
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user