diff --git a/app/Actions/CoolifyTask/PrepareCoolifyTask.php b/app/Actions/CoolifyTask/PrepareCoolifyTask.php index d4cdf64e2..686b60780 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 @@ public function __construct(CoolifyTaskArgs $remoteProcessArgs) 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 be986a76f..63e3afe2f 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 000000000..fce862eb0 --- /dev/null +++ b/app/Actions/Server/RunCommand.php @@ -0,0 +1,19 @@ +value); + + return $activity; + } +} diff --git a/app/Enums/ActivityTypes.php b/app/Enums/ActivityTypes.php index e2536a7f0..2d23cd98b 100644 --- a/app/Enums/ActivityTypes.php +++ b/app/Enums/ActivityTypes.php @@ -5,4 +5,5 @@ enum ActivityTypes: string { case INLINE = 'inline'; + case COMMAND = 'command'; } diff --git a/app/Jobs/CoolifyTask.php b/app/Jobs/CoolifyTask.php index 5418daa22..23e39a015 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 fc7f1eefc..c2d3adeea 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 @@ public function runCommand() { $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);