Have the output Marker and markTidyer.

This commit is contained in:
Joao Patricio
2023-04-01 20:50:57 +01:00
parent 829a45f410
commit 940cb3c000
5 changed files with 152 additions and 18 deletions

View File

@@ -7,7 +7,6 @@ use App\Enums\ProcessStatus;
use Illuminate\Process\ProcessResult;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;
use Spatie\Activitylog\Models\Activity;
class RunRemoteProcess
@@ -26,9 +25,12 @@ class RunRemoteProcess
protected $throttleIntervalMS = 500;
protected string $stdOutIncremental = '';
protected int $counter = 1;
protected string $stdErrIncremental = '';
public const MARK_START = "|--";
public const MARK_END = "--|";
public const SEPARATOR = '|';
public const MARK_REGEX = "/(\|--\d+\|\d+\|(?:out|err)--\|)/";
/**
* Create a new job instance.
@@ -88,15 +90,10 @@ class RunRemoteProcess
if ($this->hideFromOutput) {
return;
}
$this->currentTime = $this->elapsedTime();
if ($type === 'out') {
$this->stdOutIncremental .= $output;
} else {
$this->stdErrIncremental .= $output;
}
$this->activity->description .= $output;
$this->activity->description .= $this->encodeOutput($type, $output);
if ($this->isAfterLastThrottle()) {
// Let's write to database.
@@ -107,6 +104,16 @@ class RunRemoteProcess
}
}
public function encodeOutput($type, $output)
{
return
static::MARK_START . $this->counter++ .
static::SEPARATOR . $this->elapsedTime() .
static::SEPARATOR . $type .
static::MARK_END .
$output;
}
/**
* Determines if it's time to write again to database.
*