This commit is contained in:
Andras Bacsai
2023-05-31 12:38:36 +02:00
parent c953482ba9
commit 59f631e1d4
12 changed files with 73 additions and 55 deletions

View File

@@ -7,6 +7,7 @@ use App\Models\Server;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Sleep;
use Spatie\Activitylog\Models\Activity;
/**
@@ -76,7 +77,7 @@ function generate_ssh_command(string $private_key_location, string $server_ip, s
return $ssh_command;
}
function instant_remote_process(array $command, Server $server, $throwError = true)
function instant_remote_process(array $command, Server $server, $throwError = true, $repeat = 1)
{
$command_string = implode("\n", $command);
$private_key_location = save_private_key_for_server($server);
@@ -85,6 +86,11 @@ function instant_remote_process(array $command, Server $server, $throwError = tr
$output = trim($process->output());
$exitCode = $process->exitCode();
if ($exitCode !== 0) {
if ($repeat > 1) {
Sleep::for(200)->milliseconds();
ray('executing again');
return instant_remote_process($command, $server, $throwError, $repeat - 1);
}
ray($process->errorOutput());
if (!$throwError) {
return null;