From 9318cac1899fa3a5dfdf190fce0f89391ff5c2ce Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 12 Oct 2023 09:12:46 +0200 Subject: [PATCH] fix: service status check fix: containerStatusJob fix: service form --- app/Http/Livewire/Project/Service/Index.php | 34 ++------------- app/Http/Livewire/Project/Service/Modal.php | 4 +- app/Http/Livewire/Project/Service/Navbar.php | 11 ++--- .../Livewire/Project/Service/StackForm.php | 42 +++++++++++++++++++ app/Jobs/ContainerStatusJob.php | 4 +- .../livewire/project/service/index.blade.php | 39 ++++++----------- .../livewire/project/service/modal.blade.php | 2 +- .../livewire/project/service/navbar.blade.php | 2 +- .../project/service/stack-form.blade.php | 16 +++++++ 9 files changed, 83 insertions(+), 71 deletions(-) create mode 100644 app/Http/Livewire/Project/Service/StackForm.php create mode 100644 resources/views/livewire/project/service/stack-form.blade.php diff --git a/app/Http/Livewire/Project/Service/Index.php b/app/Http/Livewire/Project/Service/Index.php index 687732540..fba473250 100644 --- a/app/Http/Livewire/Project/Service/Index.php +++ b/app/Http/Livewire/Project/Service/Index.php @@ -13,13 +13,7 @@ class Index extends Component public $databases; public array $parameters; public array $query; - protected $rules = [ - 'service.docker_compose_raw' => 'required', - 'service.docker_compose' => 'required', - 'service.name' => 'required', - 'service.description' => 'nullable', - ]; - protected $listeners = ["saveCompose"]; + protected $listeners = ["refreshStacks","checkStatus"]; public function render() { return view('livewire.project.service.index'); @@ -32,17 +26,12 @@ class Index extends Component $this->applications = $this->service->applications->sort(); $this->databases = $this->service->databases->sort(); } - public function saveCompose($raw) - { - $this->service->docker_compose_raw = $raw; - $this->submit(); - } public function checkStatus() { dispatch_sync(new ContainerStatusJob($this->service->server)); - $this->refreshStack(); + $this->refreshStacks(); } - public function refreshStack() + public function refreshStacks() { $this->applications = $this->service->applications->sort(); $this->applications->each(function ($application) { @@ -53,21 +42,4 @@ class Index extends Component $database->refresh(); }); } - - - public function submit() - { - try { - $this->validate(); - $this->service->save(); - $this->service->parse(); - $this->service->refresh(); - $this->service->saveComposeConfigs(); - $this->refreshStack(); - $this->emit('refreshEnvs'); - $this->emit('success', 'Service saved successfully.'); - } catch (\Throwable $e) { - return handleError($e, $this); - } - } } diff --git a/app/Http/Livewire/Project/Service/Modal.php b/app/Http/Livewire/Project/Service/Modal.php index a5fd759e7..7092070f6 100644 --- a/app/Http/Livewire/Project/Service/Modal.php +++ b/app/Http/Livewire/Project/Service/Modal.php @@ -6,8 +6,8 @@ use Livewire\Component; class Modal extends Component { - public function serviceStatusUpdated() { - $this->emit('serviceStatusUpdated'); + public function checkStatus() { + $this->emit('checkStatus'); } public function render() { diff --git a/app/Http/Livewire/Project/Service/Navbar.php b/app/Http/Livewire/Project/Service/Navbar.php index 3f7679c56..d85c6f435 100644 --- a/app/Http/Livewire/Project/Service/Navbar.php +++ b/app/Http/Livewire/Project/Service/Navbar.php @@ -13,20 +13,15 @@ class Navbar extends Component public Service $service; public array $parameters; public array $query; - protected $listeners = ['serviceStatusUpdated']; public function render() { return view('livewire.project.service.navbar'); } - public function serviceStatusUpdated() + + public function checkStatus() { - $this->check_status(); - } - public function check_status() - { - dispatch_sync(new ContainerStatusJob($this->service->server)); - $this->service->refresh(); + $this->emit('checkStatus'); } public function deploy() { diff --git a/app/Http/Livewire/Project/Service/StackForm.php b/app/Http/Livewire/Project/Service/StackForm.php new file mode 100644 index 000000000..1518e3d22 --- /dev/null +++ b/app/Http/Livewire/Project/Service/StackForm.php @@ -0,0 +1,42 @@ + 'required', + 'service.docker_compose' => 'required', + 'service.name' => 'required', + 'service.description' => 'nullable', + ]; + public $service; + public function saveCompose($raw) + { + $this->service->docker_compose_raw = $raw; + $this->submit(); + } + + public function submit() + { + try { + $this->validate(); + $this->service->save(); + $this->service->parse(); + $this->service->refresh(); + $this->service->saveComposeConfigs(); + $this->emit('refreshStacks'); + $this->emit('refreshEnvs'); + $this->emit('success', 'Service saved successfully.'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function render() + { + return view('livewire.project.service.stack-form'); + } +} diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index 392819440..9b4ef5699 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -29,7 +29,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted public function __construct(public Server $server) { - $this->handle(); + } public function middleware(): array @@ -44,7 +44,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted public function handle() { try { - ray("checking server status for {$this->server->name}"); + ray("checking server status for {$this->server->id}"); // ray()->clearAll(); $serverUptimeCheckNumber = $this->server->unreachable_count; $serverUptimeCheckNumberMax = 3; diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.php index 05a90dd5d..a966c56d4 100644 --- a/resources/views/livewire/project/service/index.blade.php +++ b/resources/views/livewire/project/service/index.blade.php @@ -1,40 +1,24 @@ -
+
-
-
-
-

Service Stack

-
Configuration
-
- Save - Edit Compose - File -
-
- - -
-
+
@foreach ($applications as $application)
{{ $application->status }}
Logs + href="{{ route('project.service.logs', [...$parameters, 'service_name' => $application->name]) }}">Logs
@endforeach @foreach ($databases as $database) @@ -95,7 +80,8 @@
{{ $database->status }}
Logs + href="{{ route('project.service.logs', [...$parameters, 'service_name' => $database->name]) }}">Logs
@endforeach
@@ -126,3 +112,4 @@
+ diff --git a/resources/views/livewire/project/service/modal.blade.php b/resources/views/livewire/project/service/modal.blade.php index 8517d3ef1..2333379d0 100644 --- a/resources/views/livewire/project/service/modal.blade.php +++ b/resources/views/livewire/project/service/modal.blade.php @@ -1,5 +1,5 @@
- + diff --git a/resources/views/livewire/project/service/navbar.blade.php b/resources/views/livewire/project/service/navbar.blade.php index d18838cce..0825c2c7f 100644 --- a/resources/views/livewire/project/service/navbar.blade.php +++ b/resources/views/livewire/project/service/navbar.blade.php @@ -1,4 +1,4 @@ -
+

Configuration

diff --git a/resources/views/livewire/project/service/stack-form.blade.php b/resources/views/livewire/project/service/stack-form.blade.php new file mode 100644 index 000000000..7225770c1 --- /dev/null +++ b/resources/views/livewire/project/service/stack-form.blade.php @@ -0,0 +1,16 @@ +
+
+
+

Service Stack

+
Configuration
+
+ Save + Edit Compose + File +
+
+ + +
+