fix: service container status updates

This commit is contained in:
Andras Bacsai 2024-03-01 10:36:32 +01:00
parent 604ab0afd8
commit 5322d446bd
7 changed files with 23 additions and 45 deletions

View File

@ -10,7 +10,7 @@ class Configuration extends Component
{ {
public Application $application; public Application $application;
public $servers; public $servers;
protected $listeners = ['build_pack_updated' => '$refresh']; protected $listeners = ['buildPackUpdated' => '$refresh'];
public function mount() public function mount()
{ {

View File

@ -182,7 +182,7 @@ public function updatedApplicationBuildPack()
$this->resetDefaultLabels(false); $this->resetDefaultLabels(false);
} }
$this->submit(); $this->submit();
$this->dispatch('build_pack_updated'); $this->dispatch('buildPackUpdated');
} }
public function getWildcardDomain() public function getWildcardDomain()
{ {

View File

@ -17,9 +17,7 @@ public function getListeners()
{ {
$userId = auth()->user()->id; $userId = auth()->user()->id;
return [ return [
"echo-private:user.{$userId},ServiceStatusChanged" => 'checkStatus', "echo-private:user.{$userId},ServiceStatusChanged" => 'check_status',
"refreshStacks",
"checkStatus",
]; ];
} }
public function render() public function render()
@ -37,21 +35,10 @@ public function mount()
$this->applications = $this->service->applications->sort(); $this->applications = $this->service->applications->sort();
$this->databases = $this->service->databases->sort(); $this->databases = $this->service->databases->sort();
} }
public function checkStatus() public function check_status()
{ {
dispatch_sync(new ContainerStatusJob($this->service->server)); dispatch_sync(new ContainerStatusJob($this->service->server));
$this->refreshStacks(); $this->dispatch('refresh')->self();
$this->dispatch('serviceStatusChanged'); $this->dispatch('serviceStatusChanged');
} }
public function refreshStacks()
{
$this->applications = $this->service->applications->sort();
$this->applications->each(function ($application) {
$application->refresh();
});
$this->databases = $this->service->databases->sort();
$this->databases->each(function ($database) {
$database->refresh();
});
}
} }

View File

@ -17,7 +17,20 @@ class Navbar extends Component
public array $parameters; public array $parameters;
public array $query; public array $query;
public $isDeploymentProgress = false; public $isDeploymentProgress = false;
public function getListeners()
{
return [
"serviceStatusChanged"
];
}
public function serviceStatusChanged()
{
$this->dispatch('refresh')->self();
}
public function render()
{
return view('livewire.project.service.navbar');
}
public function checkDeployments() public function checkDeployments()
{ {
$activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first(); $activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first();
@ -28,26 +41,6 @@ public function checkDeployments()
$this->isDeploymentProgress = false; $this->isDeploymentProgress = false;
} }
} }
public function getListeners()
{
return [
"serviceStatusChanged"
];
}
public function serviceStatusChanged()
{
$this->service->refresh();
}
public function render()
{
return view('livewire.project.service.navbar');
}
public function check_status($showNotification = false)
{
dispatch_sync(new ContainerStatusJob($this->service->destination->server));
$this->service->refresh();
if ($showNotification) $this->dispatch('success', 'Service status updated.');
}
public function deploy() public function deploy()
{ {
$this->checkDeployments(); $this->checkDeployments();
@ -62,7 +55,6 @@ public function deploy()
public function stop(bool $forceCleanup = false) public function stop(bool $forceCleanup = false)
{ {
StopService::run($this->service); StopService::run($this->service);
$this->service->refresh();
if ($forceCleanup) { if ($forceCleanup) {
$this->dispatch('success', 'Containers cleaned up.'); $this->dispatch('success', 'Containers cleaned up.');
} else { } else {

View File

@ -1,4 +1,4 @@
<nav wire:poll.30000ms="check_status"> <nav wire:poll.5000ms="check_status">
<x-resources.breadcrumbs :resource="$database" :parameters="$parameters" /> <x-resources.breadcrumbs :resource="$database" :parameters="$parameters" />
<x-databases.navbar :database="$database" :parameters="$parameters" /> <x-databases.navbar :database="$database" :parameters="$parameters" />
</nav> </nav>

View File

@ -1,4 +1,4 @@
<div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'service-stack' }" x-init="$wire.checkStatus"> <div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'service-stack' }" x-init="$wire.check_status" wire:poll.5000ms="check_status">
<livewire:project.service.navbar :service="$service" :parameters="$parameters" :query="$query" /> <livewire:project.service.navbar :service="$service" :parameters="$parameters" :query="$query" />
<div class="flex h-full pt-6"> <div class="flex h-full pt-6">
<div class="flex flex-col items-start gap-4 min-w-fit"> <div class="flex flex-col items-start gap-4 min-w-fit">

View File

@ -11,7 +11,7 @@ class="inline-block w-3 h-3 rounded cursor-pointer stroke-current hover:bg-red-5
</svg> </svg>
</div> </div>
@empty @empty
<div>No tags yet</div> <div class="py-1">No tags yet</div>
@endforelse @endforelse
</div> </div>
<form wire:submit='submit' class="flex items-end gap-2 pt-4"> <form wire:submit='submit' class="flex items-end gap-2 pt-4">
@ -23,8 +23,7 @@ class="inline-block w-3 h-3 rounded cursor-pointer stroke-current hover:bg-red-5
<x-forms.button type="submit">Add</x-forms.button> <x-forms.button type="submit">Add</x-forms.button>
</form> </form>
@if ($tags->count() > 0) @if ($tags->count() > 0)
<h3 class="pt-4">Already defined tags</h3> <h3 class="pt-4">Quickly Add</h3>
<div>Click to quickly add one.</div>
<div class="flex gap-2 pt-4"> <div class="flex gap-2 pt-4">
@foreach ($tags as $tag) @foreach ($tags as $tag)
<x-forms.button wire:click="addTag('{{ $tag->id }}','{{ $tag->name }}')"> <x-forms.button wire:click="addTag('{{ $tag->id }}','{{ $tag->name }}')">