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(activity-monitor): consolidate activity monitoring logic and remove deprecated NewActivityMonitor component

Andras Bacsaia3dc3c861b99
diff --git a/app/Livewire/ActivityMonitor.php b/app/Livewire/ActivityMonitor.php
index 1a819f1c0e..398fdeb0d5 100644
--- a/app/Livewire/ActivityMonitor.php
+++ b/app/Livewire/ActivityMonitor.php
@@ -14,6 +14,8 @@ class ActivityMonitor extends Component
public $eventToDispatch = 'activityFinished';
+ public $eventData = null;
+
public $isPollingActive = false;
public bool $fullHeight = false;
@@ -26,10 +28,11 @@ class ActivityMonitor extends Component
protected $listeners = ['activityMonitor' => 'newMonitorActivity'];
- public function newMonitorActivity($activityId, $eventToDispatch = 'activityFinished')
+ public function newMonitorActivity($activityId, $eventToDispatch = 'activityFinished', $eventData = null)
{
$this->activityId = $activityId;
$this->eventToDispatch = $eventToDispatch;
+ $this->eventData = $eventData;
$this->hydrateActivity();
@@ -55,7 +58,11 @@ class ActivityMonitor extends Component
if ($user) {
$teamId = $user->currentTeam()->id;
if (! self::$eventDispatched) {
- $this->eventToDispatch::dispatch($teamId);
+ if (filled($this->eventData)) {
+ $this->eventToDispatch::dispatch($teamId, $this->eventData);
+ } else {
+ $this->eventToDispatch::dispatch($teamId);
+ }
self::$eventDispatched = true;
}
}
@@ -63,7 +70,11 @@ class ActivityMonitor extends Component
return;
}
if (! self::$eventDispatched) {
- $this->dispatch($this->eventToDispatch);
+ if (filled($this->eventData)) {
+ $this->dispatch($this->eventToDispatch, $this->eventData);
+ } else {
+ $this->dispatch($this->eventToDispatch);
+ }
self::$eventDispatched = true;
}
}
diff --git a/app/Livewire/NewActivityMonitor.php b/app/Livewire/NewActivityMonitor.php
deleted file mode 100644
index a9334e7108..0000000000
--- a/app/Livewire/NewActivityMonitor.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-namespace App\Livewire;
-
-use App\Models\User;
-use Livewire\Component;
-use Spatie\Activitylog\Models\Activity;
-
-class NewActivityMonitor extends Component
-{
- public ?string $header = null;
-
- public $activityId;
-
- public $eventToDispatch = 'activityFinished';
-
- public $eventData = null;
-
- public $isPollingActive = false;
-
- protected $activity;
-
- protected $listeners = ['newActivityMonitor' => 'newMonitorActivity'];
-
- public function newMonitorActivity($activityId, $eventToDispatch = 'activityFinished', $eventData = null)
- {
- $this->activityId = $activityId;
- $this->eventToDispatch = $eventToDispatch;
- $this->eventData = $eventData;
-
- $this->hydrateActivity();
-
- $this->isPollingActive = true;
- }
-
- public function hydrateActivity()
- {
- $this->activity = Activity::find($this->activityId);
- }
-
- public function polling()
- {
- $this->hydrateActivity();
- // $this->setStatus(ProcessStatus::IN_PROGRESS);
- $exit_code = data_get($this->activity, 'properties.exitCode');
- if ($exit_code !== null) {
- // if ($exit_code === 0) {
- // // $this->setStatus(ProcessStatus::FINISHED);
- // } else {
- // // $this->setStatus(ProcessStatus::ERROR);
- // }
- $this->isPollingActive = false;
- if ($this->eventToDispatch !== null) {
- if (str($this->eventToDispatch)->startsWith('App\\Events\\')) {
- $causer_id = data_get($this->activity, 'causer_id');
- $user = User::find($causer_id);
- if ($user) {
- foreach ($user->teams as $team) {
- $teamId = $team->id;
- $this->eventToDispatch::dispatch($teamId);
- }
- }
-
- return;
- }
- if (! is_null($this->eventData)) {
- $this->dispatch($this->eventToDispatch, $this->eventData);
- } else {
- $this->dispatch($this->eventToDispatch);
- }
- }
- }
- }
-}
diff --git a/app/Livewire/Server/ValidateAndInstall.php b/app/Livewire/Server/ValidateAndInstall.php
index ba8fd9d4f0..459b50b913 100644
--- a/app/Livewire/Server/ValidateAndInstall.php
+++ b/app/Livewire/Server/ValidateAndInstall.php
@@ -106,7 +106,8 @@ class ValidateAndInstall extends Component
if ($this->number_of_tries <= $this->max_tries) {
$activity = $this->server->installDocker();
$this->number_of_tries++;
- $this->dispatch('newActivityMonitor', $activity->id, 'init', $this->number_of_tries);
+ // $this->dispatch('newActivityMonitor', $activity->id, 'init', $this->number_of_tries);
+ $this->dispatch('activityMonitor', $activity->id, 'init', $this->number_of_tries);
}
return;
diff --git a/resources/views/livewire/new-activity-monitor.blade.php b/resources/views/livewire/new-activity-monitor.blade.php
deleted file mode 100644
index 6bd1f82cae..0000000000
--- a/resources/views/livewire/new-activity-monitor.blade.php
+++ /dev/null
@@ -1,18 +0,0 @@
-@php use App\Actions\CoolifyTask\RunRemoteProcess; @endphp
-<div>
- @if ($this->activity)
- @if (isset($header))
- <div class="flex gap-2 pb-2">
- {{ $header }}
- @if ($isPollingActive)
- <x-loading />
- @endif
- </div>
- @endif
- <div
- class="scrollbar flex flex-col-reverse w-full overflow-y-auto border border-solid rounded-sm border-coolgray-300 max-h-[32rem] p-4 pt-6 text-xs dark:text-white">
-
- <pre class="font-mono whitespace-pre-wrap" @if ($isPollingActive) wire:poll.1000ms="polling" @endif>{{ RunRemoteProcess::decodeOutput($this->activity) }}</pre>
- </div>
- @endif
-</div>
diff --git a/resources/views/livewire/server/validate-and-install.blade.php b/resources/views/livewire/server/validate-and-install.blade.php
index b7d86a4ca3..b57e0425a7 100644
--- a/resources/views/livewire/server/validate-and-install.blade.php
+++ b/resources/views/livewire/server/validate-and-install.blade.php
@@ -120,7 +120,7 @@
@endif
@endif
- <livewire:new-activity-monitor header="Docker Installation Logs" />
+ <livewire:activity-monitor header="Docker Installation Logs" />
@isset($error)
<pre class="font-bold whitespace-pre-line text-error">{!! $error !!}</pre>
@endisset