Refactoring: extract process handling from async job.

This commit is contained in:
Joao Patricio
2023-03-21 10:32:38 +00:00
parent 34c9265aa9
commit 29fb40bd16
6 changed files with 27 additions and 39 deletions

View File

@@ -1,19 +1,29 @@
<?php
use App\Actions\RemoteProcess\DispatchRemoteProcess;
use App\Data\RemoteProcessArgs;
use Spatie\Activitylog\Contracts\Activity;
if (! function_exists('remoteProcess')) {
/**
* Run a Coolify Process, which SSH's into a machine to run the command(s).
* Run a Coolify Process, which SSH's asynchronously into a machine to run the command(s).
* @TODO Change 'root' to 'coolify' when it's able to run Docker commands without sudo
*
*/
function remoteProcess($command, $destination): Activity
function remoteProcess(
string $command,
string $destination,
?int $port = 22,
?string $user = 'root',
): Activity
{
return resolve(DispatchRemoteProcess::class, [
'destination' => $destination,
'command' => $command,
'remoteProcessArgs' => new RemoteProcessArgs(
destination: $destination,
command: $command,
port: $port,
user: $user,
),
])();
}
}