fix: logs page style
This commit is contained in:
@@ -152,6 +152,14 @@ func (h *ServerSchedulerHandler) OnTaskExecuting(req *executor.ExecutionRequest)
|
|||||||
return nil, nil, fmt.Errorf("创建日志收集器失败: %v", err)
|
return nil, nil, fmt.Errorf("创建日志收集器失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 记录到内存缓冲
|
||||||
|
h.es.UpdateResult(executor.ExecutionResult{
|
||||||
|
TaskID: req.TaskID,
|
||||||
|
LogID: req.LogID,
|
||||||
|
Status: constant.TaskStatusRunning,
|
||||||
|
StartTime: time.Now(),
|
||||||
|
})
|
||||||
|
|
||||||
// 对于本地任务,Scheduler 会通过返回的 Writer 写入日志
|
// 对于本地任务,Scheduler 会通过返回的 Writer 写入日志
|
||||||
// 对于远程任务,Scheduler 不会写入任何内容(由 Agent 推送至此 TL)
|
// 对于远程任务,Scheduler 不会写入任何内容(由 Agent 推送至此 TL)
|
||||||
return tl, tl, nil
|
return tl, tl, nil
|
||||||
@@ -234,6 +242,9 @@ func (h *ServerSchedulerHandler) OnTaskCompleted(req *executor.ExecutionRequest,
|
|||||||
|
|
||||||
// 处理任务完成(更新统计、清理旧日志等)
|
// 处理任务完成(更新统计、清理旧日志等)
|
||||||
h.es.taskLogService.ProcessTaskCompletion(taskLog)
|
h.es.taskLogService.ProcessTaskCompletion(taskLog)
|
||||||
|
|
||||||
|
// 更新内存缓冲
|
||||||
|
h.es.UpdateResult(*result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ServerSchedulerHandler) OnTaskFailed(req *executor.ExecutionRequest, err error) {
|
func (h *ServerSchedulerHandler) OnTaskFailed(req *executor.ExecutionRequest, err error) {
|
||||||
@@ -283,6 +294,16 @@ func (h *ServerSchedulerHandler) OnTaskFailed(req *executor.ExecutionRequest, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.es.taskLogService.ProcessTaskCompletion(taskLog)
|
h.es.taskLogService.ProcessTaskCompletion(taskLog)
|
||||||
|
|
||||||
|
// 更新内存缓冲
|
||||||
|
h.es.UpdateResult(executor.ExecutionResult{
|
||||||
|
TaskID: req.TaskID,
|
||||||
|
LogID: req.LogID,
|
||||||
|
Status: constant.TaskStatusFailed,
|
||||||
|
Error: err.Error(),
|
||||||
|
StartTime: time.Now(),
|
||||||
|
EndTime: time.Now(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ServerSchedulerHandler) OnCronNextRun(req *executor.ExecutionRequest, nextRun time.Time) {
|
func (h *ServerSchedulerHandler) OnCronNextRun(req *executor.ExecutionRequest, nextRun time.Time) {
|
||||||
@@ -561,11 +582,58 @@ func (es *ExecutorService) ExecuteCommandWithOptions(command string, timeout tim
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateResult 更新内存中的执行结果缓冲
|
||||||
|
func (es *ExecutorService) UpdateResult(res executor.ExecutionResult) {
|
||||||
|
es.resultsMu.Lock()
|
||||||
|
defer es.resultsMu.Unlock()
|
||||||
|
|
||||||
|
// 按照用户要求,任务结束后清空 Output 以节省内存。
|
||||||
|
// 结束状态的任务如果需要查看完整日志,会自动从数据库/文件中读取。
|
||||||
|
isFinished := res.Status == constant.TaskStatusSuccess ||
|
||||||
|
res.Status == constant.TaskStatusFailed ||
|
||||||
|
res.Status == constant.TaskStatusTimeout ||
|
||||||
|
res.Status == constant.TaskStatusCancelled
|
||||||
|
|
||||||
|
if isFinished {
|
||||||
|
res.Output = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找是否已存在(通过 LogID)
|
||||||
|
for i := range es.results {
|
||||||
|
if es.results[i].LogID == res.LogID && res.LogID != 0 {
|
||||||
|
es.results[i] = res
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不存在则追加到末尾
|
||||||
|
if len(es.results) >= 100 {
|
||||||
|
// 移除最旧的一个
|
||||||
|
es.results = es.results[1:]
|
||||||
|
}
|
||||||
|
es.results = append(es.results, res)
|
||||||
|
}
|
||||||
|
|
||||||
// GetLastResults returns the last execution results
|
// GetLastResults returns the last execution results
|
||||||
func (es *ExecutorService) GetLastResults(count int) []executor.ExecutionResult {
|
func (es *ExecutorService) GetLastResults(count int) []executor.ExecutionResult {
|
||||||
es.resultsMu.RLock()
|
es.resultsMu.RLock()
|
||||||
defer es.resultsMu.RUnlock()
|
defer es.resultsMu.RUnlock()
|
||||||
return nil
|
|
||||||
|
total := len(es.results)
|
||||||
|
if count > total {
|
||||||
|
count = total
|
||||||
|
}
|
||||||
|
|
||||||
|
if count <= 0 {
|
||||||
|
return []executor.ExecutionResult{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回副本,按时间倒序(最新的在前)
|
||||||
|
res := make([]executor.ExecutionResult, 0, count)
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
|
res = append(res, es.results[total-1-i])
|
||||||
|
}
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- 以下内容从 TaskExecutionService 合并 ---
|
// --- 以下内容从 TaskExecutionService 合并 ---
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
|
|
||||||
<div class="flex flex-col lg:flex-row gap-4">
|
<div class="flex flex-col lg:flex-row gap-4">
|
||||||
<!-- 日志列表 -->
|
<!-- 日志列表 -->
|
||||||
<div class="flex-1 min-w-0 rounded-lg border bg-card overflow-hidden">
|
<div class="flex-1 min-w-0 rounded-lg border bg-card overflow-hidden flex flex-col">
|
||||||
<!-- 小屏表头 -->
|
<!-- 小屏表头 -->
|
||||||
<div
|
<div
|
||||||
class="flex sm:hidden items-center gap-2 px-3 py-2 border-b bg-muted/20 text-xs text-muted-foreground font-medium">
|
class="flex sm:hidden items-center gap-2 px-3 py-2 border-b bg-muted/20 text-xs text-muted-foreground font-medium">
|
||||||
@@ -276,7 +276,7 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
</div>
|
</div>
|
||||||
<!-- 大屏表头 -->
|
<!-- 大屏表头 -->
|
||||||
<div
|
<div
|
||||||
class="hidden sm:flex items-center gap-4 px-4 py-2 border-b bg-muted/20 text-sm text-muted-foreground font-medium">
|
class="hidden sm:flex items-center gap-4 px-4 h-11 border-b bg-muted/20 text-sm text-muted-foreground font-medium">
|
||||||
<span class="w-16 shrink-0">ID</span>
|
<span class="w-16 shrink-0">ID</span>
|
||||||
<span class="w-12 shrink-0 text-center">类型</span>
|
<span class="w-12 shrink-0 text-center">类型</span>
|
||||||
<span class="w-36 shrink-0">任务名称</span>
|
<span class="w-36 shrink-0">任务名称</span>
|
||||||
@@ -286,7 +286,7 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
<span v-if="!selectedLog" class="w-40 text-right shrink-0 hidden md:block">执行时间</span>
|
<span v-if="!selectedLog" class="w-40 text-right shrink-0 hidden md:block">执行时间</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- 列表 -->
|
<!-- 列表 -->
|
||||||
<div class="divide-y">
|
<div class="divide-y flex-1">
|
||||||
<div v-if="logs.length === 0" class="text-sm text-muted-foreground text-center py-8">
|
<div v-if="logs.length === 0" class="text-sm text-muted-foreground text-center py-8">
|
||||||
暂无日志
|
暂无日志
|
||||||
</div>
|
</div>
|
||||||
@@ -329,7 +329,7 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
<span class="w-12 text-right shrink-0 text-muted-foreground text-xs">{{ formatDuration(log.duration)
|
<span class="w-12 text-right shrink-0 text-muted-foreground text-xs">{{ formatDuration(log.duration)
|
||||||
}}</span>
|
}}</span>
|
||||||
</div>
|
</div>
|
||||||
<!-- 大屏行 -->
|
<!-- 大屏行 -->
|
||||||
<div class="hidden sm:flex items-center gap-4 px-4 py-2">
|
<div class="hidden sm:flex items-center gap-4 px-4 py-2">
|
||||||
@@ -369,7 +369,7 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
<span class="w-16 text-right shrink-0 text-muted-foreground text-xs">{{ formatDuration(log.duration)
|
<span class="w-16 text-right shrink-0 text-muted-foreground text-xs">{{ formatDuration(log.duration)
|
||||||
}}</span>
|
}}</span>
|
||||||
<span v-if="!selectedLog"
|
<span v-if="!selectedLog"
|
||||||
class="w-40 text-right shrink-0 text-muted-foreground text-xs hidden md:block">{{ log.start_time ||
|
class="w-40 text-right shrink-0 text-muted-foreground text-xs hidden md:block">{{ log.start_time ||
|
||||||
log.created_at }}</span>
|
log.created_at }}</span>
|
||||||
@@ -382,10 +382,10 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
|
|
||||||
<!-- 日志详情侧边栏 -->
|
<!-- 日志详情侧边栏 -->
|
||||||
<div v-if="selectedLog"
|
<div v-if="selectedLog"
|
||||||
class="w-full lg:w-[480px] rounded-lg border bg-card flex flex-col overflow-hidden shrink-0 max-h-[60vh] lg:max-h-[calc(100vh-180px)]">
|
class="w-full lg:w-[480px] rounded-lg border bg-card flex flex-col overflow-hidden shrink-0 max-h-[80vh] lg:max-h-none">
|
||||||
<div class="flex items-center justify-between px-4 py-3 border-b">
|
<div class="flex items-center justify-between px-4 h-11 border-b bg-muted/20">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span class="text-sm font-medium">日志详情</span>
|
<span class="text-sm font-medium text-muted-foreground">日志详情</span>
|
||||||
<Button v-if="selectedLog.status === TASK_STATUS.RUNNING" variant="destructive" size="sm"
|
<Button v-if="selectedLog.status === TASK_STATUS.RUNNING" variant="destructive" size="sm"
|
||||||
class="h-6 px-2 text-[10px]" :disabled="isStopping" @click="stopTask">
|
class="h-6 px-2 text-[10px]" :disabled="isStopping" @click="stopTask">
|
||||||
{{ isStopping ? '停止中...' : '停止任务' }}
|
{{ isStopping ? '停止中...' : '停止任务' }}
|
||||||
@@ -396,11 +396,11 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-4 py-3 border-b space-y-2 text-sm">
|
<div class="px-4 py-3 border-b space-y-2 text-sm">
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between items-center h-6">
|
||||||
<span class="text-muted-foreground">任务名称</span>
|
<span class="text-muted-foreground">任务名称</span>
|
||||||
<span class="font-medium">{{ selectedLog.task_name }}</span>
|
<span class="font-medium">{{ selectedLog.task_name }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center h-8">
|
||||||
<span class="text-muted-foreground">状态</span>
|
<span class="text-muted-foreground">状态</span>
|
||||||
<Badge variant="outline" :class="[
|
<Badge variant="outline" :class="[
|
||||||
'capitalize px-3 py-1 font-semibold rounded-full border shadow-sm transition-all duration-300',
|
'capitalize px-3 py-1 font-semibold rounded-full border shadow-sm transition-all duration-300',
|
||||||
@@ -418,21 +418,22 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
</div>
|
</div>
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between items-center h-6">
|
||||||
<span class="text-muted-foreground">耗时</span>
|
<span class="text-muted-foreground">耗时</span>
|
||||||
<span>{{ formatDuration(selectedLog.duration) }}</span>
|
<span class="font-medium">{{ formatDuration(selectedLog.duration) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between items-center h-6">
|
||||||
<span class="text-muted-foreground">开始时间</span>
|
<span class="text-muted-foreground">开始时间</span>
|
||||||
<span>{{ selectedLog.start_time || '-' }}</span>
|
<span class="font-mono text-xs">{{ selectedLog.start_time || '-' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between items-center h-6">
|
||||||
<span class="text-muted-foreground">结束时间</span>
|
<span class="text-muted-foreground">结束时间</span>
|
||||||
<span>{{ selectedLog.end_time || '-' }}</span>
|
<span class="font-mono text-xs">{{ selectedLog.end_time || '-' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="pt-1">
|
<div class="pt-1.5">
|
||||||
<span class="text-muted-foreground">命令</span>
|
<span class="text-muted-foreground block mb-1">执行命令</span>
|
||||||
<code class="mt-1 block font-mono bg-muted/40 px-2 py-1 rounded text-xs break-all">
|
<code
|
||||||
|
class="block font-mono bg-muted/40 px-3 py-2 rounded text-xs break-all border border-muted-foreground/10">
|
||||||
{{ selectedLog.command }}
|
{{ selectedLog.command }}
|
||||||
</code>
|
</code>
|
||||||
</div>
|
</div>
|
||||||
@@ -447,14 +448,15 @@ watch(() => route.query.task_id, (newTaskId) => {
|
|||||||
{{ selectedLog.error }}
|
{{ selectedLog.error }}
|
||||||
</code>
|
</code>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-4 py-2 text-sm text-muted-foreground border-b bg-muted/20 flex items-center justify-between">
|
<div class="px-4 py-2.5 text-sm text-muted-foreground border-b bg-muted/20 flex items-center justify-between">
|
||||||
<span>输出</span>
|
<span class="font-medium">日志输出</span>
|
||||||
<Button variant="ghost" size="icon" class="h-6 w-6" @click="showFullscreen = true" title="全屏查看">
|
<Button variant="ghost" size="icon" class="h-6 w-6" @click="showFullscreen = true" title="全屏查看">
|
||||||
<Maximize2 class="h-3.5 w-3.5" />
|
<Maximize2 class="h-3.5 w-3.5" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-1 overflow-auto">
|
<div class="flex-1 overflow-auto bg-muted/5 min-h-[160px]">
|
||||||
<pre class="p-4 text-xs font-mono whitespace-pre-wrap break-all log-pre">{{ decompressedOutput }}</pre>
|
<pre
|
||||||
|
class="p-4 text-xs font-mono whitespace-pre-wrap break-all log-pre leading-relaxed">{{ decompressedOutput }}</pre>
|
||||||
<div v-if="isWsLoading" class="p-4 text-sm text-muted-foreground italic">连接中...</div>
|
<div v-if="isWsLoading" class="p-4 text-sm text-muted-foreground italic">连接中...</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user