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: run user commands on high prio queue

Andras Bacsai58fc897ea5b2
diff --git a/app/Actions/CoolifyTask/PrepareCoolifyTask.php b/app/Actions/CoolifyTask/PrepareCoolifyTask.php
index d4cdf64e23..686b60780e 100644
--- a/app/Actions/CoolifyTask/PrepareCoolifyTask.php
+++ b/app/Actions/CoolifyTask/PrepareCoolifyTask.php
@@ -3,6 +3,7 @@
namespace App\Actions\CoolifyTask;
use App\Data\CoolifyTaskArgs;
+use App\Enums\ActivityTypes;
use App\Jobs\CoolifyTask;
use Spatie\Activitylog\Models\Activity;
@@ -40,8 +41,18 @@ 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, call_event_data: $this->remoteProcessArgs->call_event_data);
- dispatch($job);
+ $job = new CoolifyTask(
+ activity: $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,
+ );
+ if ($this->remoteProcessArgs->type === ActivityTypes::COMMAND->value) {
+ ray('Dispatching a high priority job');
+ dispatch($job)->onQueue('high');
+ } else {
+ dispatch($job);
+ }
$this->activity->refresh();
return $this->activity;
diff --git a/app/Actions/CoolifyTask/RunRemoteProcess.php b/app/Actions/CoolifyTask/RunRemoteProcess.php
index be986a76fb..63e3afe2f9 100644
--- a/app/Actions/CoolifyTask/RunRemoteProcess.php
+++ b/app/Actions/CoolifyTask/RunRemoteProcess.php
@@ -39,7 +39,7 @@ class RunRemoteProcess
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) {
+ if ($activity->getExtraProperty('type') !== ActivityTypes::INLINE->value && $activity->getExtraProperty('type') !== ActivityTypes::COMMAND->value) {
throw new \RuntimeException('Incompatible Activity to run a remote command.');
}
diff --git a/app/Actions/Server/RunCommand.php b/app/Actions/Server/RunCommand.php
new file mode 100644
index 0000000000..fce862eb08
--- /dev/null
+++ b/app/Actions/Server/RunCommand.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Actions\Server;
+
+use App\Enums\ActivityTypes;
+use App\Models\Server;
+use Lorisleiva\Actions\Concerns\AsAction;
+
+class RunCommand
+{
+ use AsAction;
+
+ public function handle(Server $server, $command)
+ {
+ $activity = remote_process(command: [$command], server: $server, ignore_errors: true, type: ActivityTypes::COMMAND->value);
+
+ return $activity;
+ }
+}
diff --git a/app/Enums/ActivityTypes.php b/app/Enums/ActivityTypes.php
index e2536a7f02..2d23cd98ba 100644
--- a/app/Enums/ActivityTypes.php
+++ b/app/Enums/ActivityTypes.php
@@ -5,4 +5,5 @@ namespace App\Enums;
enum ActivityTypes: string
{
case INLINE = 'inline';
+ case COMMAND = 'command';
}
diff --git a/app/Jobs/CoolifyTask.php b/app/Jobs/CoolifyTask.php
index 5418daa223..23e39a0150 100755
--- a/app/Jobs/CoolifyTask.php
+++ b/app/Jobs/CoolifyTask.php
@@ -20,10 +20,11 @@ class CoolifyTask implements ShouldBeEncrypted, ShouldQueue
*/
public function __construct(
public Activity $activity,
- public bool $ignore_errors = false,
- public $call_event_on_finish = null,
- public $call_event_data = null
- ) {}
+ public bool $ignore_errors,
+ public $call_event_on_finish,
+ public $call_event_data,
+ ) {
+ }
/**
* Execute the job.
diff --git a/app/Livewire/RunCommand.php b/app/Livewire/RunCommand.php
index fc7f1eefcb..c2d3adeeac 100644
--- a/app/Livewire/RunCommand.php
+++ b/app/Livewire/RunCommand.php
@@ -2,6 +2,7 @@
namespace App\Livewire;
+use App\Actions\Server\RunCommand as ServerRunCommand;
use App\Models\Server;
use Livewire\Component;
@@ -33,7 +34,7 @@ class RunCommand extends Component
{
$this->validate();
try {
- $activity = remote_process([$this->command], Server::where('uuid', $this->server)->first(), ignore_errors: true);
+ $activity = ServerRunCommand::run(server: Server::where('uuid', $this->server)->first(), command: $this->command);
$this->dispatch('activityMonitor', $activity->id);
} catch (\Throwable $e) {
return handleError($e, $this);