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.

fix: startproxy event fix: add data to async remove processes

Andras Bacsai2509406d1c1c
diff --git a/app/Actions/CoolifyTask/PrepareCoolifyTask.php b/app/Actions/CoolifyTask/PrepareCoolifyTask.php
index b5b5a8853e..e6a5497562 100644
--- a/app/Actions/CoolifyTask/PrepareCoolifyTask.php
+++ b/app/Actions/CoolifyTask/PrepareCoolifyTask.php
@@ -39,7 +39,7 @@ class PrepareCoolifyTask
public function __invoke(): Activity
{
- $job = new CoolifyTask($this->activity, ignore_errors: $this->remoteProcessArgs->ignore_errors, call_event_on_finish: $this->remoteProcessArgs->call_event_on_finish);
+ $job = new CoolifyTask($this->activity, ignore_errors: $this->remoteProcessArgs->ignore_errors, call_event_on_finish: $this->remoteProcessArgs->call_event_on_finish, call_event_data: $this->remoteProcessArgs->call_event_data);
dispatch($job);
$this->activity->refresh();
return $this->activity;
diff --git a/app/Actions/CoolifyTask/RunRemoteProcess.php b/app/Actions/CoolifyTask/RunRemoteProcess.php
index 327d46c68f..737b4babe6 100644
--- a/app/Actions/CoolifyTask/RunRemoteProcess.php
+++ b/app/Actions/CoolifyTask/RunRemoteProcess.php
@@ -21,6 +21,8 @@ class RunRemoteProcess
public $call_event_on_finish = null;
+ public $call_event_data = null;
+
protected $time_start;
protected $current_time;
@@ -34,7 +36,7 @@ class RunRemoteProcess
/**
* Create a new job instance.
*/
- public function __construct(Activity $activity, bool $hide_from_output = false, bool $ignore_errors = false, $call_event_on_finish = null)
+ public function __construct(Activity $activity, bool $hide_from_output = false, bool $ignore_errors = false, $call_event_on_finish = null, $call_event_data = null)
{
if ($activity->getExtraProperty('type') !== ActivityTypes::INLINE->value) {
@@ -45,6 +47,7 @@ class RunRemoteProcess
$this->hide_from_output = $hide_from_output;
$this->ignore_errors = $ignore_errors;
$this->call_event_on_finish = $call_event_on_finish;
+ $this->call_event_data = $call_event_data;
}
public static function decodeOutput(?Activity $activity = null): string
@@ -111,9 +114,16 @@ class RunRemoteProcess
}
if ($this->call_event_on_finish) {
try {
- event(resolve("App\\Events\\$this->call_event_on_finish", [
- 'userId' => $this->activity->causer_id,
- ]));
+ ray($this->call_event_data);
+ if ($this->call_event_data) {
+ event(resolve("App\\Events\\$this->call_event_on_finish", [
+ "data" => $this->call_event_data,
+ ]));
+ } else {
+ event(resolve("App\\Events\\$this->call_event_on_finish", [
+ 'userId' => $this->activity->causer_id,
+ ]));
+ }
} catch (\Throwable $e) {
ray($e);
}
diff --git a/app/Actions/Proxy/StartProxy.php b/app/Actions/Proxy/StartProxy.php
index a781ab4427..ab635fc65d 100644
--- a/app/Actions/Proxy/StartProxy.php
+++ b/app/Actions/Proxy/StartProxy.php
@@ -2,7 +2,7 @@
namespace App\Actions\Proxy;
-use App\Events\ProxyStatusChanged;
+use App\Events\ProxyStarted;
use App\Models\Server;
use Illuminate\Support\Str;
use Lorisleiva\Actions\Concerns\AsAction;
@@ -54,13 +54,14 @@ class StartProxy
}
if ($async) {
- $activity = remote_process($commands, $server);
+ $activity = remote_process($commands, $server, callEventOnFinish: 'ProxyStarted', callEventData: $server);
return $activity;
} else {
instant_remote_process($commands, $server);
$server->proxy->set('status', 'running');
$server->proxy->set('type', $proxyType);
$server->save();
+ ProxyStarted::dispatch($server);
return 'OK';
}
} catch (\Throwable $e) {
diff --git a/app/Data/CoolifyTaskArgs.php b/app/Data/CoolifyTaskArgs.php
index cc717561ff..e1e43f2f0f 100644
--- a/app/Data/CoolifyTaskArgs.php
+++ b/app/Data/CoolifyTaskArgs.php
@@ -21,6 +21,7 @@ class CoolifyTaskArgs extends Data
public ?string $status = null ,
public bool $ignore_errors = false,
public $call_event_on_finish = null,
+ public $call_event_data = null
) {
if(is_null($status)){
$this->status = ProcessStatus::QUEUED->value;
diff --git a/app/Events/ProxyStarted.php b/app/Events/ProxyStarted.php
new file mode 100644
index 0000000000..c77fe08b0b
--- /dev/null
+++ b/app/Events/ProxyStarted.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Events;
+
+use App\Models\Server;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+class ProxyStarted
+{
+ use Dispatchable, InteractsWithSockets, SerializesModels;
+ public function __construct(public Server $server)
+ {
+ }
+}
diff --git a/app/Jobs/CoolifyTask.php b/app/Jobs/CoolifyTask.php
index 77d453ae29..56c4eee223 100755
--- a/app/Jobs/CoolifyTask.php
+++ b/app/Jobs/CoolifyTask.php
@@ -21,7 +21,8 @@ class CoolifyTask implements ShouldQueue, ShouldBeEncrypted
public function __construct(
public Activity $activity,
public bool $ignore_errors = false,
- public $call_event_on_finish = null
+ public $call_event_on_finish = null,
+ public $call_event_data = null
) {
}
@@ -33,7 +34,8 @@ class CoolifyTask implements ShouldQueue, ShouldBeEncrypted
$remote_process = resolve(RunRemoteProcess::class, [
'activity' => $this->activity,
'ignore_errors' => $this->ignore_errors,
- 'call_event_on_finish' => $this->call_event_on_finish
+ 'call_event_on_finish' => $this->call_event_on_finish,
+ 'call_event_data' => $this->call_event_data
]);
$remote_process();
diff --git a/app/Listeners/ProxyStartedNotification.php b/app/Listeners/ProxyStartedNotification.php
new file mode 100644
index 0000000000..62131c22af
--- /dev/null
+++ b/app/Listeners/ProxyStartedNotification.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Listeners;
+
+use App\Events\ProxyStarted;
+use App\Models\Server;
+
+class ProxyStartedNotification
+{
+ public Server $server;
+ public function __construct()
+ {
+ }
+
+ public function handle(ProxyStarted $event): void
+ {
+ $this->server = data_get($event, 'server');
+ $this->server->setupDefault404Redirect();
+ $this->server->setupDynamicProxyConfiguration();
+ }
+}
diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php
index a9b4496b4d..0e9be72d1a 100644
--- a/app/Providers/EventServiceProvider.php
+++ b/app/Providers/EventServiceProvider.php
@@ -2,8 +2,10 @@
namespace App\Providers;
+use App\Events\ProxyStarted;
use App\Listeners\MaintenanceModeDisabledNotification;
use App\Listeners\MaintenanceModeEnabledNotification;
+use App\Listeners\ProxyStartedNotification;
use Illuminate\Foundation\Events\MaintenanceModeDisabled;
use Illuminate\Foundation\Events\MaintenanceModeEnabled;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
@@ -17,9 +19,9 @@ class EventServiceProvider extends ServiceProvider
MaintenanceModeDisabled::class => [
MaintenanceModeDisabledNotification::class,
],
- // Registered::class => [
- // SendEmailVerificationNotification::class,
- // ],
+ ProxyStarted::class => [
+ ProxyStartedNotification::class,
+ ],
];
public function boot(): void
{
diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php
index 13905391e9..0aba82ea16 100644
--- a/bootstrap/helpers/remoteProcess.php
+++ b/bootstrap/helpers/remoteProcess.php
@@ -24,7 +24,8 @@ function remote_process(
?string $type_uuid = null,
?Model $model = null,
bool $ignore_errors = false,
- $callEventOnFinish = null
+ $callEventOnFinish = null,
+ $callEventData = null
): Activity {
if (is_null($type)) {
$type = ActivityTypes::INLINE->value;
@@ -50,6 +51,7 @@ function remote_process(
model: $model,
ignore_errors: $ignore_errors,
call_event_on_finish: $callEventOnFinish,
+ call_event_data: $callEventData,
),
])();
}
diff --git a/resources/views/livewire/server/proxy.blade.php b/resources/views/livewire/server/proxy.blade.php
index 60828ec3d5..49bf654a6c 100644
--- a/resources/views/livewire/server/proxy.blade.php
+++ b/resources/views/livewire/server/proxy.blade.php
@@ -13,7 +13,10 @@
<x-forms.button type="submit">Save</x-forms.button>
</div>
- <div class="pb-4 ">Before switching proxies, please read <a
+ <div class="pb-4 "> <svg class="inline-flex w-6 h-6 mr-2 text-warning" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
+ <path fill="currentColor"
+ d="M240.26 186.1L152.81 34.23a28.74 28.74 0 0 0-49.62 0L15.74 186.1a27.45 27.45 0 0 0 0 27.71A28.31 28.31 0 0 0 40.55 228h174.9a28.31 28.31 0 0 0 24.79-14.19a27.45 27.45 0 0 0 .02-27.71m-20.8 15.7a4.46 4.46 0 0 1-4 2.2H40.55a4.46 4.46 0 0 1-4-2.2a3.56 3.56 0 0 1 0-3.73L124 46.2a4.77 4.77 0 0 1 8 0l87.44 151.87a3.56 3.56 0 0 1 .02 3.73M116 136v-32a12 12 0 0 1 24 0v32a12 12 0 0 1-24 0m28 40a16 16 0 1 1-16-16a16 16 0 0 1 16 16" />
+ </svg>Before switching proxies, please read <a class="text-white underline"
href="https://coolify.io/docs/server/switching-proxies">this</a>.</div>
@if ($server->proxyType() === 'TRAEFIK_V2')
<div class="pb-4">Traefik v2</div>