From 6b936a3e92ef7cc47772a1930b7ea7c3b488fbb0 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 9 Dec 2024 11:36:39 +0100 Subject: [PATCH] feat: able to download schedule task logs --- .../Shared/ScheduledTask/Executions.php | 21 ++++++-- .../scheduled-task/executions.blade.php | 53 ++++++++++--------- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/app/Livewire/Project/Shared/ScheduledTask/Executions.php b/app/Livewire/Project/Shared/ScheduledTask/Executions.php index dae1733f5..af86229d2 100644 --- a/app/Livewire/Project/Shared/ScheduledTask/Executions.php +++ b/app/Livewire/Project/Shared/ScheduledTask/Executions.php @@ -25,8 +25,11 @@ class Executions extends Component public ?string $serverTimezone = null; public $currentPage = 1; + public $logsPerPage = 100; + public $selectedExecution = null; + public $isPollingActive = false; public function getListeners() @@ -74,12 +77,13 @@ class Executions extends Component $this->selectedExecution = null; $this->currentPage = 1; $this->isPollingActive = false; + return; } $this->selectedKey = $key; $this->selectedExecution = $this->task->executions()->find($key); $this->currentPage = 1; - + // Start polling if task is running if ($this->selectedExecution && $this->selectedExecution->status === 'running') { $this->isPollingActive = true; @@ -103,24 +107,33 @@ class Executions extends Component public function getLogLinesProperty() { - if (!$this->selectedExecution) { + if (! $this->selectedExecution) { return collect(); } - if (!$this->selectedExecution->message) { + if (! $this->selectedExecution->message) { return collect(['Waiting for task output...']); } $lines = collect(explode("\n", $this->selectedExecution->message)); + return $lines->take($this->currentPage * $this->logsPerPage); } + public function downloadLogs() + { + return response()->streamDownload(function () { + echo $this->selectedExecution->message; + }, 'task-execution-'.$this->selectedExecution->id.'.log'); + } + public function hasMoreLogs() { - if (!$this->selectedExecution || !$this->selectedExecution->message) { + if (! $this->selectedExecution || ! $this->selectedExecution->message) { return false; } $lines = collect(explode("\n", $this->selectedExecution->message)); + return $lines->count() > ($this->currentPage * $this->logsPerPage); } diff --git a/resources/views/livewire/project/shared/scheduled-task/executions.blade.php b/resources/views/livewire/project/shared/scheduled-task/executions.blade.php index 2ded710a6..6afc78a76 100644 --- a/resources/views/livewire/project/shared/scheduled-task/executions.blade.php +++ b/resources/views/livewire/project/shared/scheduled-task/executions.blade.php @@ -1,18 +1,17 @@ -
+