This commit is contained in:
Andras Bacsai 2023-06-08 10:55:50 +02:00
parent b3cdd7df3c
commit 0add4155ab
9 changed files with 41 additions and 38 deletions

View File

@ -2,6 +2,7 @@
namespace App\Http\Livewire\Project\Application; namespace App\Http\Livewire\Project\Application;
use App\Jobs\ApplicationContainerStatusJob;
use App\Jobs\ContainerStopJob; use App\Jobs\ContainerStopJob;
use App\Models\Application; use App\Models\Application;
use Livewire\Component; use Livewire\Component;
@ -68,4 +69,12 @@ class Deploy extends Component
$this->application->save(); $this->application->save();
$this->emit('applicationStatusChanged'); $this->emit('applicationStatusChanged');
} }
public function pollStatus()
{
dispatch(new ApplicationContainerStatusJob(
application: $this->application,
container_name: generate_container_name($this->application->uuid),
));
}
} }

View File

@ -35,6 +35,7 @@ class ApplicationContainerStatusJob implements ShouldQueue, ShouldBeUnique
{ {
try { try {
$status = get_container_status(server: $this->application->destination->server, container_id: $this->container_name, throwError: false); $status = get_container_status(server: $this->application->destination->server, container_id: $this->container_name, throwError: false);
ray('ApplicationContainerStatusJob', $status);
if ($this->pull_request_id) { if ($this->pull_request_id) {
$preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->application->id, $this->pull_request_id); $preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->application->id, $this->pull_request_id);
$preview->status = $status; $preview->status = $status;
@ -47,11 +48,4 @@ class ApplicationContainerStatusJob implements ShouldQueue, ShouldBeUnique
Log::error($e->getMessage()); Log::error($e->getMessage());
} }
} }
protected function check_container_status()
{
if ($this->application->destination->server) {
$this->application->status = get_container_status(server: $this->application->destination->server, container_id: $this->application->uuid);
$this->application->save();
}
}
} }

View File

@ -0,0 +1,5 @@
<x-loading wire:loading.delay.longer />
<div class="flex items-center gap-2 text-sm" wire:loading.remove.delay.longer>
<div class="badge badge-error badge-xs"></div>
<div class="text-xs font-medium tracking-wide text-error">Stopped</div>
</div>

View File

@ -0,0 +1,5 @@
<x-loading wire:loading.delay.longer />
<div class="flex items-center gap-2 text-sm" wire:loading.remove.delay.longer>
<div class="badge badge-success badge-xs"></div>
<div class="text-xs font-medium tracking-wide text-success">Running</div>
</div>

View File

@ -0,0 +1,5 @@
<x-loading wire:loading.delay.longer />
<div class="flex items-center gap-2 text-sm" wire:loading.remove.delay.longer>
<div class="badge badge-error badge-xs"></div>
<div class="text-xs font-medium tracking-wide text-error">Stopped</div>
</div>

View File

@ -1,4 +1,4 @@
<div class="flex items-center gap-2"> <div class="flex items-center gap-2" wire:poll="pollStatus">
<div class="group"> <div class="group">
<label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Actions <label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Actions
<x-chevron-down /> <x-chevron-down />
@ -8,8 +8,9 @@
<ul tabindex="0" class="text-xs text-white normal-case rounded min-w-max menu bg-coolgray-200"> <ul tabindex="0" class="text-xs text-white normal-case rounded min-w-max menu bg-coolgray-200">
<li> <li>
<div class="rounded-none hover:bg-coollabs" wire:click='deploy'><svg <div class="rounded-none hover:bg-coollabs" wire:click='deploy'><svg
xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24" stroke-width="1.5" xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24"
stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" /> <path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4" /> <path d="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4" />
<path d="M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4" /> <path d="M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4" />

View File

@ -54,15 +54,11 @@
<div class="flex flex-col p-4 bg-coolgray-200 " x-init="$wire.loadStatus('{{ data_get($preview, 'pull_request_id') }}')"> <div class="flex flex-col p-4 bg-coolgray-200 " x-init="$wire.loadStatus('{{ data_get($preview, 'pull_request_id') }}')">
<div class="flex gap-2">PR #{{ data_get($preview, 'pull_request_id') }} | <div class="flex gap-2">PR #{{ data_get($preview, 'pull_request_id') }} |
@if (data_get($preview, 'status') === 'running') @if (data_get($preview, 'status') === 'running')
<div class="flex items-center gap-2"> <x-status.running />
<div class="badge badge-success badge-xs"></div> @elseif (data_get($preview, 'status') === 'restarting')
<div class="text-xs font-medium tracking-wide">Running</div> <x-status.restarting />
</div>
@else @else
<div class="flex items-center gap-2"> <x-status.stopped />
<div class="badge badge-error badge-xs"></div>
<div class="text-xs font-medium tracking-wide">Stopped</div>
</div>
@endif @endif
@if (data_get($preview, 'status') !== 'exited') @if (data_get($preview, 'status') !== 'exited')
| <a target="_blank" href="{{ data_get($preview, 'fqdn') }}">Open Preview | <a target="_blank" href="{{ data_get($preview, 'fqdn') }}">Open Preview

View File

@ -1,15 +1,9 @@
<div wire:poll.5000ms='applicationStatusChanged'> <div wire:poll.5000ms='applicationStatusChanged'>
@if ($application->status === 'running') @if ($application->status === 'running')
<x-loading wire:loading.delay.longer /> <x-status.running />
<div class="flex items-center gap-2 text-sm" wire:loading.remove.delay.longer> @elseif($application->status === 'restarting')
<div class="badge badge-success badge-xs"></div> <x-status.restarting />
<div class="text-xs font-medium tracking-wide">Running</div>
</div>
@else @else
<x-loading wire:loading.delay.longer /> <x-status.stopped />
<div class="flex items-center gap-2 text-sm" wire:loading.remove.delay.longer>
<div class="badge badge-error badge-xs"></div>
<div class="text-xs font-medium tracking-wide">Stopped</div>
</div>
@endif @endif
</div> </div>

View File

@ -2,17 +2,11 @@
@if ($server->settings->is_validated) @if ($server->settings->is_validated)
<div wire:poll.10000ms="proxyStatus"> <div wire:poll.10000ms="proxyStatus">
@if ($server->extra_attributes->proxy_status === 'running') @if ($server->extra_attributes->proxy_status === 'running')
<x-loading wire:loading.delay.longer /> <x-status.running />
<div class="flex items-center gap-2" wire:loading.remove.delay.longer> @elseif ($server->extra_attributes->proxy_status === 'restarting')
<div class="badge badge-success badge-xs"></div> <x-status.restarting />
<div class="text-xs font-medium tracking-wide">Running</div>
</div>
@else @else
<x-loading wire:loading.delay.longer /> <x-status.stopped />
<div class="flex items-center gap-2" wire:loading.remove.delay.longer>
<div class="badge badge-error badge-xs"></div>
<div class="text-xs font-medium tracking-wide">Stopped</div>
</div>
@endif @endif
</div> </div>
@endif @endif