2024-01-07 15:23:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\Project\Service;
|
|
|
|
|
2024-05-07 13:41:50 +00:00
|
|
|
use App\Actions\Docker\GetContainersStatus;
|
2024-01-07 15:23:41 +00:00
|
|
|
use App\Models\Service;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Configuration extends Component
|
|
|
|
{
|
2024-01-31 12:46:40 +00:00
|
|
|
public ?Service $service = null;
|
2024-01-07 15:23:41 +00:00
|
|
|
public $applications;
|
|
|
|
public $databases;
|
|
|
|
public array $parameters;
|
|
|
|
public array $query;
|
|
|
|
public function getListeners()
|
|
|
|
{
|
|
|
|
$userId = auth()->user()->id;
|
|
|
|
return [
|
2024-03-01 09:36:32 +00:00
|
|
|
"echo-private:user.{$userId},ServiceStatusChanged" => 'check_status',
|
2024-04-11 13:42:37 +00:00
|
|
|
"check_status",
|
|
|
|
"refresh" => '$refresh',
|
2024-01-07 15:23:41 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.project.service.configuration');
|
|
|
|
}
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->parameters = get_route_parameters();
|
|
|
|
$this->query = request()->query();
|
2024-01-24 11:26:14 +00:00
|
|
|
$this->service = Service::whereUuid($this->parameters['service_uuid'])->first();
|
|
|
|
if (!$this->service) {
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
2024-01-07 15:23:41 +00:00
|
|
|
$this->applications = $this->service->applications->sort();
|
|
|
|
$this->databases = $this->service->databases->sort();
|
|
|
|
}
|
2024-03-25 10:33:38 +00:00
|
|
|
public function restartApplication($id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$application = $this->service->applications->find($id);
|
|
|
|
if ($application) {
|
|
|
|
$application->restart();
|
|
|
|
$this->dispatch('success', 'Application restarted successfully.');
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function restartDatabase($id)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$database = $this->service->databases->find($id);
|
|
|
|
if ($database) {
|
|
|
|
$database->restart();
|
|
|
|
$this->dispatch('success', 'Database restarted successfully.');
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
2024-03-01 09:36:32 +00:00
|
|
|
public function check_status()
|
2024-01-07 15:23:41 +00:00
|
|
|
{
|
2024-03-14 08:21:48 +00:00
|
|
|
try {
|
2024-05-07 13:41:50 +00:00
|
|
|
GetContainersStatus::run($this->service->server);
|
|
|
|
// dispatch_sync(new ContainerStatusJob($this->service->server));
|
2024-03-14 08:21:48 +00:00
|
|
|
$this->dispatch('refresh')->self();
|
2024-04-12 11:15:24 +00:00
|
|
|
$this->dispatch('updateStatus');
|
2024-03-14 08:21:48 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
2024-01-07 15:23:41 +00:00
|
|
|
}
|
|
|
|
}
|