Changes output to JSON serialization.
This commit is contained in:
@@ -27,11 +27,6 @@ class RunRemoteProcess
|
||||
|
||||
protected int $counter = 1;
|
||||
|
||||
public const MARK_START = "|--";
|
||||
public const MARK_END = "--|";
|
||||
public const SEPARATOR = '|';
|
||||
public const MARK_REGEX = "/(\|--\d+\|\d+\|(?:out|err)--\|)/";
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
@@ -93,7 +88,7 @@ class RunRemoteProcess
|
||||
|
||||
$this->currentTime = $this->elapsedTime();
|
||||
|
||||
$this->activity->description .= $this->encodeOutput($type, $output);
|
||||
$this->activity->description = $this->encodeOutput($type, $output);
|
||||
|
||||
if ($this->isAfterLastThrottle()) {
|
||||
// Let's write to database.
|
||||
@@ -106,12 +101,37 @@ class RunRemoteProcess
|
||||
|
||||
public function encodeOutput($type, $output)
|
||||
{
|
||||
return
|
||||
static::MARK_START . $this->counter++ .
|
||||
static::SEPARATOR . $this->elapsedTime() .
|
||||
static::SEPARATOR . $type .
|
||||
static::MARK_END .
|
||||
$output;
|
||||
$outputStack = json_decode($this->activity->description, associative: true, flags: JSON_THROW_ON_ERROR);
|
||||
|
||||
$outputStack[] = [
|
||||
'type' => $type,
|
||||
'output' => $output,
|
||||
'elapsed_tim' => $this->elapsedTime(),
|
||||
'order' => $this->counter++,
|
||||
];
|
||||
|
||||
return json_encode($outputStack, flags: JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
public static function decodeOutput(?Activity $activity = null): string
|
||||
{
|
||||
if(is_null($activity)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
$decoded = json_decode(data_get($activity, 'description'),
|
||||
associative: true,
|
||||
flags: JSON_THROW_ON_ERROR
|
||||
);
|
||||
} catch (\JsonException $exception) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return collect($decoded)
|
||||
->sortBy(fn($i) => $i['order'])
|
||||
->map(fn($i) => $i['output'])
|
||||
->implode("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user