Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

refactor: application status changed realtime

Andras Bacsai1fd12832caa5
diff --git a/app/Events/ApplicationStatusChanged.php b/app/Events/ApplicationStatusChanged.php
new file mode 100644
index 0000000000..4224d4a299
--- /dev/null
+++ b/app/Events/ApplicationStatusChanged.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Events;
+
+use Illuminate\Broadcasting\Channel;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Broadcasting\PresenceChannel;
+use Illuminate\Broadcasting\PrivateChannel;
+use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+class ApplicationStatusChanged implements ShouldBroadcast
+{
+ use Dispatchable, InteractsWithSockets, SerializesModels;
+ public $teamId;
+ public function __construct($teamId = null)
+ {
+ if (is_null($teamId)) {
+ $teamId = auth()->user()->currentTeam()->id ?? null;
+ }
+ if (is_null($teamId)) {
+ throw new \Exception("Team id is null");
+ }
+ $this->teamId = $teamId;
+ }
+
+ public function broadcastOn(): array
+ {
+ return [
+ new PrivateChannel("team.{$this->teamId}"),
+ ];
+ }
+}
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 4de85f6ae2..08c3880846 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -4,6 +4,7 @@ namespace App\Jobs;
use App\Enums\ApplicationDeploymentStatus;
use App\Enums\ProxyTypes;
+use App\Events\ApplicationStatusChanged;
use App\Models\Application;
use App\Models\ApplicationDeploymentQueue;
use App\Models\ApplicationPreview;
@@ -266,6 +267,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
"ignore_errors" => true,
]
);
+ ApplicationStatusChanged::dispatch(data_get($this->application,'environment.project.team.id'));
}
}
private function push_to_docker_registry()
@@ -1246,6 +1248,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
}
private function build_by_compose_file() {
+ $this->application_deployment_queue->addLogEntry("Pulling & building required images.");
if ($this->application->build_pack === 'dockerimage') {
$this->application_deployment_queue->addLogEntry("Pulling latest images from the registry.");
$this->execute_remote_command(
diff --git a/app/Livewire/Project/Application/Heading.php b/app/Livewire/Project/Application/Heading.php
index 0762c5105b..3db5fc9c4e 100644
--- a/app/Livewire/Project/Application/Heading.php
+++ b/app/Livewire/Project/Application/Heading.php
@@ -3,6 +3,7 @@
namespace App\Livewire\Project\Application;
use App\Actions\Application\StopApplication;
+use App\Events\ApplicationStatusChanged;
use App\Jobs\ContainerStatusJob;
use App\Jobs\ServerStatusJob;
use App\Models\Application;
@@ -15,13 +16,19 @@ class Heading extends Component
public array $parameters;
protected string $deploymentUuid;
-
+ public function getListeners()
+ {
+ $teamId = auth()->user()->currentTeam()->id;
+ return [
+ "echo-private:team.{$teamId},ApplicationStatusChanged" => 'check_status',
+ ];
+ }
public function mount()
{
$this->parameters = get_route_parameters();
}
- public function check_status()
+ public function check_status($showNotification = false)
{
if ($this->application->destination->server->isFunctional()) {
dispatch(new ContainerStatusJob($this->application->destination->server));
@@ -32,6 +39,7 @@ class Heading extends Component
} else {
dispatch(new ServerStatusJob($this->application->destination->server));
}
+ if ($showNotification) $this->dispatch('success', 'Application status updated.');
}
public function force_deploy_without_cache()
diff --git a/app/Livewire/Project/Database/Heading.php b/app/Livewire/Project/Database/Heading.php
index 59ddf26447..76b36a5ba7 100644
--- a/app/Livewire/Project/Database/Heading.php
+++ b/app/Livewire/Project/Database/Heading.php
@@ -34,10 +34,11 @@ class Heading extends Component
$this->check_status();
}
- public function check_status()
+ public function check_status($showNotification = false)
{
dispatch_sync(new ContainerStatusJob($this->database->destination->server));
$this->database->refresh();
+ if ($showNotification) $this->dispatch('success', 'Database status updated.');
}
public function mount()
diff --git a/app/Livewire/Project/Service/Navbar.php b/app/Livewire/Project/Service/Navbar.php
index 71ec4e702b..3e2c3485c7 100644
--- a/app/Livewire/Project/Service/Navbar.php
+++ b/app/Livewire/Project/Service/Navbar.php
@@ -41,9 +41,11 @@ class Navbar extends Component
{
return view('livewire.project.service.navbar');
}
- public function checkStatus()
+ 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()
{
diff --git a/resources/views/components/status/index.blade.php b/resources/views/components/status/index.blade.php
index 67fef1282e..050025f944 100644
--- a/resources/views/components/status/index.blade.php
+++ b/resources/views/components/status/index.blade.php
@@ -5,3 +5,11 @@
@else
<x-status.stopped :status="$status" />
@endif
+@if (!str($status)->contains('exited'))
+ <button title="Refresh Status" wire:click='check_status(true)' class="mx-1 hover:fill-white fill-warning">
+ <svg class="w-4 h-4" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path
+ d="M12 2a10.016 10.016 0 0 0-7 2.877V3a1 1 0 1 0-2 0v4.5a1 1 0 0 0 1 1h4.5a1 1 0 0 0 0-2H6.218A7.98 7.98 0 0 1 20 12a1 1 0 0 0 2 0A10.012 10.012 0 0 0 12 2zm7.989 13.5h-4.5a1 1 0 0 0 0 2h2.293A7.98 7.98 0 0 1 4 12a1 1 0 0 0-2 0a9.986 9.986 0 0 0 16.989 7.133V21a1 1 0 0 0 2 0v-4.5a1 1 0 0 0-1-1z" />
+ </svg>
+ </button>
+@endif
diff --git a/resources/views/components/status/services.blade.php b/resources/views/components/status/services.blade.php
index 71ea084112..dfcec74806 100644
--- a/resources/views/components/status/services.blade.php
+++ b/resources/views/components/status/services.blade.php
@@ -7,3 +7,11 @@
@else
<x-status.stopped :status="$complexStatus" />
@endif
+@if (!str($complexStatus)->contains('exited'))
+ <button title="Refresh Status" wire:click='check_status(true)' class="mx-1 hover:fill-white fill-warning">
+ <svg class="w-4 h-4" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path
+ d="M12 2a10.016 10.016 0 0 0-7 2.877V3a1 1 0 1 0-2 0v4.5a1 1 0 0 0 1 1h4.5a1 1 0 0 0 0-2H6.218A7.98 7.98 0 0 1 20 12a1 1 0 0 0 2 0A10.012 10.012 0 0 0 12 2zm7.989 13.5h-4.5a1 1 0 0 0 0 2h2.293A7.98 7.98 0 0 1 4 12a1 1 0 0 0-2 0a9.986 9.986 0 0 0 16.989 7.133V21a1 1 0 0 0 2 0v-4.5a1 1 0 0 0-1-1z" />
+ </svg>
+ </button>
+@endif
diff --git a/resources/views/livewire/project/application/heading.blade.php b/resources/views/livewire/project/application/heading.blade.php
index ca76d38e81..2b9f189c29 100644
--- a/resources/views/livewire/project/application/heading.blade.php
+++ b/resources/views/livewire/project/application/heading.blade.php
@@ -1,4 +1,4 @@
-<nav x-init="$wire.check_status" wire:poll.10000ms="check_status">
+<nav wire:poll.30000ms="check_status">
<x-resources.breadcrumbs :resource="$application" :parameters="$parameters" />
<x-applications.navbar :application="$application" :parameters="$parameters" />
</nav>
diff --git a/resources/views/livewire/project/database/heading.blade.php b/resources/views/livewire/project/database/heading.blade.php
index 72a52b0995..0a9734810a 100644
--- a/resources/views/livewire/project/database/heading.blade.php
+++ b/resources/views/livewire/project/database/heading.blade.php
@@ -1,4 +1,4 @@
-<nav x-init="$wire.check_status" wire:poll.10000ms="check_status">
+<nav wire:poll.30000ms="check_status">
<x-resources.breadcrumbs :resource="$database" :parameters="$parameters" />
<x-databases.navbar :database="$database" :parameters="$parameters" />
</nav>