package webcmd
import (
"fmt"
"net/http"
"time"
)
func (this *App) Serve_TaskInfo(w http.ResponseWriter, task_ref string) {
this.tasksMtx.RLock()
taskinfo, ok := this.tasks[task_ref]
this.tasksMtx.RUnlock()
if !ok {
http.Error(w, "Unknown task.", 404)
return
}
w.Header().Set("Content-Type", "text/html;charset=UTF-8")
w.WriteHeader(200)
this.ServePartial_Header(w, "/taskinfo/...")
fmt.Fprintf(w, `
- Type: %s
- Start time: %s
`,
"???",
hesc(time.Unix(taskinfo.started, 0).Format(time.RFC822Z)),
)
if taskinfo.Finished() {
fmt.Fprintf(w, `
- Completed at: %s
- Process exit code: %d
`,
hesc(time.Unix(taskinfo.stopped, 0).Format(time.RFC822Z)),
taskinfo.exitCode,
)
}
fmt.Fprint(w, `
Message |
`)
for _, line := range taskinfo.output {
messageClass := "stdout"
if line.isError {
messageClass = "stderr"
}
fmt.Fprintf(w,
`
%s |
`, messageClass, hesc(line.text),
)
}
fmt.Fprintf(w, `
`,
hesc(task_ref),
)
this.ServePartial_Footer(w)
}