TaskLog fix

This commit is contained in:
2026-01-19 17:10:43 +03:00
parent 2d2435642d
commit 3bbe320949
2 changed files with 184 additions and 98 deletions

View File

@@ -1,3 +1,11 @@
<!-- [DEF:TaskManagementPage:Component] -->
<!--
@SEMANTICS: tasks, management, history, logs
@PURPOSE: Page for managing and monitoring tasks.
@LAYER: Page
@RELATION: USES -> TaskList
@RELATION: USES -> TaskLogViewer
-->
<script>
import { onMount, onDestroy } from 'svelte';
import { getTasks, createTask, getEnvironmentsList } from '../../lib/api';
@@ -14,11 +22,13 @@
let selectedEnvId = '';
// [DEF:loadInitialData:Function]
/* @PURPOSE: Loads tasks and environments on page initialization.
@PRE: API must be reachable.
@POST: tasks and environments variables are populated.
*/
/**
* @purpose Loads tasks and environments on page initialization.
* @pre API must be reachable.
* @post tasks and environments variables are populated.
*/
async function loadInitialData() {
console.log("[loadInitialData][Action] Loading initial tasks and environments");
try {
loading = true;
const [tasksData, envsData] = await Promise.all([
@@ -27,8 +37,9 @@
]);
tasks = tasksData;
environments = envsData;
console.log(`[loadInitialData][Coherence:OK] Data loaded context={{'tasks': ${tasks.length}, 'envs': ${environments.length}}}`);
} catch (error) {
console.error('Failed to load tasks data:', error);
console.error(`[loadInitialData][Coherence:Failed] Failed to load tasks data context={{'error': '${error.message}'}}`);
} finally {
loading = false;
}
@@ -36,10 +47,11 @@
// [/DEF:loadInitialData:Function]
// [DEF:refreshTasks:Function]
/* @PURPOSE: Periodically refreshes the task list.
@PRE: API must be reachable.
@POST: tasks variable is updated if data is valid.
*/
/**
* @purpose Periodically refreshes the task list.
* @pre API must be reachable.
* @post tasks variable is updated if data is valid.
*/
async function refreshTasks() {
try {
const data = await getTasks();
@@ -48,40 +60,45 @@
tasks = data;
}
} catch (error) {
console.error('Failed to refresh tasks:', error);
console.error(`[refreshTasks][Coherence:Failed] Failed to refresh tasks context={{'error': '${error.message}'}}`);
}
}
// [/DEF:refreshTasks:Function]
// [DEF:handleSelectTask:Function]
/* @PURPOSE: Updates the selected task ID when a task is clicked.
@PRE: event.detail.id must be provided.
@POST: selectedTaskId is updated.
*/
/**
* @purpose Updates the selected task ID when a task is clicked.
* @pre event.detail.id must be provided.
* @post selectedTaskId is updated.
*/
function handleSelectTask(event) {
selectedTaskId = event.detail.id;
console.log(`[handleSelectTask][Action] Task selected context={{'taskId': '${selectedTaskId}'}}`);
}
// [/DEF:handleSelectTask:Function]
// [DEF:handleRunBackup:Function]
/* @PURPOSE: Triggers a manual backup task for the selected environment.
@PRE: selectedEnvId must not be empty.
@POST: Backup task is created and task list is refreshed.
*/
/**
* @purpose Triggers a manual backup task for the selected environment.
* @pre selectedEnvId must not be empty.
* @post Backup task is created and task list is refreshed.
*/
async function handleRunBackup() {
if (!selectedEnvId) {
addToast('Please select an environment', 'error');
return;
}
console.log(`[handleRunBackup][Action] Starting backup for env context={{'envId': '${selectedEnvId}'}}`);
try {
const task = await createTask('superset-backup', { environment_id: selectedEnvId });
addToast('Backup task started', 'success');
showBackupModal = false;
selectedTaskId = task.id;
await refreshTasks();
console.log(`[handleRunBackup][Coherence:OK] Backup task created context={{'taskId': '${task.id}'}}`);
} catch (error) {
console.error('Failed to start backup:', error);
console.error(`[handleRunBackup][Coherence:Failed] Failed to start backup context={{'error': '${error.message}'}}`);
}
}
// [/DEF:handleRunBackup:Function]
@@ -117,7 +134,11 @@
<h2 class="text-lg font-semibold mb-3 text-gray-700">Task Details & Logs</h2>
{#if selectedTaskId}
<div class="bg-white rounded-lg shadow-lg h-[600px] flex flex-col">
<TaskLogViewer taskId={selectedTaskId} />
<TaskLogViewer
taskId={selectedTaskId}
taskStatus={tasks.find(t => t.id === selectedTaskId)?.status}
inline={true}
/>
</div>
{:else}
<div class="bg-gray-50 border-2 border-dashed border-gray-300 rounded-lg h-[600px] flex items-center justify-center text-gray-500">
@@ -161,4 +182,6 @@
</div>
</div>
</div>
{/if}
{/if}
<!-- [/DEF:TaskManagementPage:Component] -->