mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
bcda6f6fe6
- Replace all "Load More" / "Show More" buttons with Pagination components in model-list, bot-compaction, and bot-heartbeat views - Convert backend log APIs (compaction, heartbeat, schedule) from cursor-based (before+limit) to offset+limit pagination with total_count - Update SQL queries to use OFFSET+LIMIT and add COUNT queries - Add shared parseOffsetLimit helper in handler_helpers.go - Regenerate sqlc, Swagger docs, and TypeScript SDK - Clean up unused i18n keys (loadMore, showMore, history.loadMore)
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package command
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func (h *Handler) buildHeartbeatGroup() *CommandGroup {
|
|
g := newCommandGroup("heartbeat", "View heartbeat logs")
|
|
g.DefaultAction = "logs"
|
|
g.Register(SubCommand{
|
|
Name: "logs",
|
|
Usage: "logs - List recent heartbeat logs",
|
|
Handler: func(cc CommandContext) (string, error) {
|
|
items, _, err := h.heartbeatService.ListLogs(cc.Ctx, cc.BotID, 10, 0)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if len(items) == 0 {
|
|
return "No heartbeat logs found.", nil
|
|
}
|
|
records := make([][]kv, 0, len(items))
|
|
for _, item := range items {
|
|
dur := ""
|
|
if item.CompletedAt != nil {
|
|
dur = fmt.Sprintf("%.1fs", item.CompletedAt.Sub(item.StartedAt).Seconds())
|
|
}
|
|
errMsg := ""
|
|
if item.ErrorMessage != "" {
|
|
errMsg = truncate(item.ErrorMessage, 50)
|
|
}
|
|
rec := []kv{
|
|
{"Time", item.StartedAt.Format("01-02 15:04:05")},
|
|
{"Status", item.Status},
|
|
}
|
|
if dur != "" {
|
|
rec = append(rec, kv{"Duration", dur})
|
|
}
|
|
if errMsg != "" {
|
|
rec = append(rec, kv{"Error", errMsg})
|
|
}
|
|
records = append(records, rec)
|
|
}
|
|
return formatItems(records), nil
|
|
},
|
|
})
|
|
return g
|
|
}
|