fix: order
feat: add batch counter
This commit is contained in:
parent
040e5a5198
commit
174fc76fb8
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Enums\ActivityTypes;
|
||||
use App\Enums\ProcessStatus;
|
||||
use App\Jobs\DeployApplicationJob;
|
||||
use Illuminate\Process\ProcessResult;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
@ -69,6 +70,15 @@ public function __invoke(): ProcessResult
|
||||
return $processResult;
|
||||
}
|
||||
|
||||
protected function getLatestCounter(): int
|
||||
{
|
||||
$description = json_decode($this->activity->description, associative: true, flags: JSON_THROW_ON_ERROR);
|
||||
if ($description === null || count($description) === 0) {
|
||||
return 1;
|
||||
}
|
||||
return end($description)['order'] + 1;
|
||||
}
|
||||
|
||||
protected function getCommand(): string
|
||||
{
|
||||
$user = $this->activity->getExtraProperty('user');
|
||||
@ -106,8 +116,9 @@ public function encodeOutput($type, $output)
|
||||
$outputStack[] = [
|
||||
'type' => $type,
|
||||
'output' => $output,
|
||||
'elapsed_time' => $this->elapsedTime(),
|
||||
'order' => $this->counter++,
|
||||
'timestamp' => hrtime(true),
|
||||
'batch' => DeployApplicationJob::$batch_counter,
|
||||
'order' => $this->getLatestCounter(),
|
||||
];
|
||||
|
||||
return json_encode($outputStack, flags: JSON_THROW_ON_ERROR);
|
||||
@ -115,12 +126,13 @@ public function encodeOutput($type, $output)
|
||||
|
||||
public static function decodeOutput(?Activity $activity = null): string
|
||||
{
|
||||
if(is_null($activity)) {
|
||||
if (is_null($activity)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
$decoded = json_decode(data_get($activity, 'description'),
|
||||
$decoded = json_decode(
|
||||
data_get($activity, 'description'),
|
||||
associative: true,
|
||||
flags: JSON_THROW_ON_ERROR
|
||||
);
|
||||
@ -129,9 +141,9 @@ public static function decodeOutput(?Activity $activity = null): string
|
||||
}
|
||||
|
||||
return collect($decoded)
|
||||
->sortBy(fn($i) => $i['order'])
|
||||
->map(fn($i) => $i['output'])
|
||||
->implode("\n");
|
||||
->sortBy(fn ($i) => $i['order'])
|
||||
->map(fn ($i) => $i['output'])
|
||||
->implode("");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,6 +33,7 @@ class DeployApplicationJob implements ShouldQueue
|
||||
protected Activity $activity;
|
||||
protected string $git_commit;
|
||||
protected string $workdir;
|
||||
public static int $batch_counter = 0;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
@ -93,14 +94,14 @@ public function handle(): void
|
||||
"echo -n 'Pulling latest version of the builder image (ghcr.io/coollabsio/coolify-builder)... '",
|
||||
"docker run --pull=always -d --name {$this->deployment_uuid} --rm -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/coollabsio/coolify-builder >/dev/null 2>&1",
|
||||
"echo 'Done.'",
|
||||
], 'docker_pull_builder_image');
|
||||
]);
|
||||
|
||||
// Import git repository
|
||||
$this->executeNow([
|
||||
"echo -n 'Importing {$this->application->git_repository}:{$this->application->git_branch} to {$this->workdir}... '",
|
||||
$this->gitImport(),
|
||||
"echo 'Done.'"
|
||||
], 'importing_git_repository');
|
||||
]);
|
||||
|
||||
// Get git commit
|
||||
$this->executeNow([$this->execute_in_builder("cd {$this->workdir} && git rev-parse HEAD")], 'commit_sha', hideFromOutput: true);
|
||||
@ -256,6 +257,7 @@ private function set_labels_for_applications()
|
||||
|
||||
private function executeNow(array $command, string $propertyName = null, bool $hideFromOutput = false, $setStatus = false)
|
||||
{
|
||||
static::$batch_counter++;
|
||||
$commandText = collect($command)->implode("\n");
|
||||
|
||||
$this->activity->properties = $this->activity->properties->merge([
|
||||
|
Loading…
Reference in New Issue
Block a user