feat: able to download schedule task logs
This commit is contained in:
@@ -25,8 +25,11 @@ class Executions extends Component
|
|||||||
public ?string $serverTimezone = null;
|
public ?string $serverTimezone = null;
|
||||||
|
|
||||||
public $currentPage = 1;
|
public $currentPage = 1;
|
||||||
|
|
||||||
public $logsPerPage = 100;
|
public $logsPerPage = 100;
|
||||||
|
|
||||||
public $selectedExecution = null;
|
public $selectedExecution = null;
|
||||||
|
|
||||||
public $isPollingActive = false;
|
public $isPollingActive = false;
|
||||||
|
|
||||||
public function getListeners()
|
public function getListeners()
|
||||||
@@ -74,12 +77,13 @@ class Executions extends Component
|
|||||||
$this->selectedExecution = null;
|
$this->selectedExecution = null;
|
||||||
$this->currentPage = 1;
|
$this->currentPage = 1;
|
||||||
$this->isPollingActive = false;
|
$this->isPollingActive = false;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->selectedKey = $key;
|
$this->selectedKey = $key;
|
||||||
$this->selectedExecution = $this->task->executions()->find($key);
|
$this->selectedExecution = $this->task->executions()->find($key);
|
||||||
$this->currentPage = 1;
|
$this->currentPage = 1;
|
||||||
|
|
||||||
// Start polling if task is running
|
// Start polling if task is running
|
||||||
if ($this->selectedExecution && $this->selectedExecution->status === 'running') {
|
if ($this->selectedExecution && $this->selectedExecution->status === 'running') {
|
||||||
$this->isPollingActive = true;
|
$this->isPollingActive = true;
|
||||||
@@ -103,24 +107,33 @@ class Executions extends Component
|
|||||||
|
|
||||||
public function getLogLinesProperty()
|
public function getLogLinesProperty()
|
||||||
{
|
{
|
||||||
if (!$this->selectedExecution) {
|
if (! $this->selectedExecution) {
|
||||||
return collect();
|
return collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->selectedExecution->message) {
|
if (! $this->selectedExecution->message) {
|
||||||
return collect(['Waiting for task output...']);
|
return collect(['Waiting for task output...']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$lines = collect(explode("\n", $this->selectedExecution->message));
|
$lines = collect(explode("\n", $this->selectedExecution->message));
|
||||||
|
|
||||||
return $lines->take($this->currentPage * $this->logsPerPage);
|
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()
|
public function hasMoreLogs()
|
||||||
{
|
{
|
||||||
if (!$this->selectedExecution || !$this->selectedExecution->message) {
|
if (! $this->selectedExecution || ! $this->selectedExecution->message) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$lines = collect(explode("\n", $this->selectedExecution->message));
|
$lines = collect(explode("\n", $this->selectedExecution->message));
|
||||||
|
|
||||||
return $lines->count() > ($this->currentPage * $this->logsPerPage);
|
return $lines->count() > ($this->currentPage * $this->logsPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,18 +1,17 @@
|
|||||||
<div class="flex flex-col gap-4"
|
<div class="flex flex-col gap-4" x-data="{
|
||||||
x-data="{
|
init() {
|
||||||
init() {
|
let interval;
|
||||||
let interval;
|
$wire.$watch('isPollingActive', value => {
|
||||||
$wire.$watch('isPollingActive', value => {
|
if (value) {
|
||||||
if (value) {
|
interval = setInterval(() => {
|
||||||
interval = setInterval(() => {
|
$wire.polling();
|
||||||
$wire.polling();
|
}, 1000);
|
||||||
}, 1000);
|
} else {
|
||||||
} else {
|
if (interval) clearInterval(interval);
|
||||||
if (interval) clearInterval(interval);
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}">
|
||||||
}">
|
|
||||||
@forelse($executions as $execution)
|
@forelse($executions as $execution)
|
||||||
<a wire:click="selectTask({{ data_get($execution, 'id') }})" @class([
|
<a wire:click="selectTask({{ data_get($execution, 'id') }})" @class([
|
||||||
'flex flex-col border-l-2 transition-colors p-4 cursor-pointer',
|
'flex flex-col border-l-2 transition-colors p-4 cursor-pointer',
|
||||||
@@ -45,15 +44,21 @@
|
|||||||
@endif
|
@endif
|
||||||
@if ($this->logLines->isNotEmpty())
|
@if ($this->logLines->isNotEmpty())
|
||||||
<div>
|
<div>
|
||||||
<pre class="whitespace-pre-wrap">@foreach($this->logLines as $line){{ $line }}
|
<pre class="whitespace-pre-wrap">
|
||||||
@endforeach</pre>
|
@foreach ($this->logLines as $line)
|
||||||
@if ($this->hasMoreLogs())
|
{{ $line }}
|
||||||
<div class="flex justify-center mt-4">
|
@endforeach
|
||||||
<button wire:click="loadMoreLogs" class="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50">
|
</pre>
|
||||||
Load More Logs
|
<div class="flex gap-2">
|
||||||
</button>
|
@if ($this->hasMoreLogs())
|
||||||
</div>
|
<x-forms.button wire:click.prevent="loadMoreLogs" isHighlighted>
|
||||||
@endif
|
Load More
|
||||||
|
</x-forms.button>
|
||||||
|
@endif
|
||||||
|
<x-forms.button wire:click.prevent="downloadLogs" isHighlighted>
|
||||||
|
Download
|
||||||
|
</x-forms.button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
<div>No output was recorded for this execution.</div>
|
<div>No output was recorded for this execution.</div>
|
||||||
|
Reference in New Issue
Block a user