feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
49
internal/webapp/handlers_logs.go
Обычный файл
49
internal/webapp/handlers_logs.go
Обычный файл
@@ -0,0 +1,49 @@
|
||||
package webapp
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// handleLogs tails the in-memory worker log buffer. The handler
|
||||
// reads ?tail=200|500|1000|5000 (default 200) per section 6.6.
|
||||
func (s *Server) handleLogs(w http.ResponseWriter, r *http.Request) {
|
||||
writeNoStore(w)
|
||||
sess, _ := sessionFromContext(r.Context())
|
||||
tail := parseTail(r.URL.Query().Get("tail"))
|
||||
lines := s.logBuffer.Tail(tail)
|
||||
data := logsPageData{
|
||||
basePageData: s.newBasePage(r, "Worker logs", sess),
|
||||
Tail: tail,
|
||||
Lines: lines,
|
||||
BufferSize: s.logBuffer.Size(),
|
||||
BufferCap: s.logBuffer.Cap(),
|
||||
}
|
||||
if err := s.templates.Execute(w, "logs.html", data); err != nil {
|
||||
s.deps.Logger.Printf("render logs: %v", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// parseTail clamps the requested tail count to one of the
|
||||
// doc-prescribed buckets (200/500/1000/5000) and falls back to 200.
|
||||
func parseTail(raw string) int {
|
||||
n, err := strconv.Atoi(raw)
|
||||
if err != nil {
|
||||
return 200
|
||||
}
|
||||
for _, allowed := range []int{200, 500, 1000, 5000} {
|
||||
if n == allowed {
|
||||
return allowed
|
||||
}
|
||||
}
|
||||
return 200
|
||||
}
|
||||
|
||||
type logsPageData struct {
|
||||
basePageData
|
||||
Tail int
|
||||
Lines []string
|
||||
BufferSize int
|
||||
BufferCap int
|
||||
}
|
||||
Ссылка в новой задаче
Block a user