mirror of
https://github.com/kopia/kopia.git
synced 2026-01-24 06:18:02 -05:00
* uitask: added package for managing and introspection into tasks running inside the process * server: added API for getting details of tasks running inside the server * htmlui: added new tab called 'Tasks' This allows access to progres, logs and cancelation for long-running tasks (Snapshots, Maintenance, and in the future Restore, Estimate, Verify) * snapshot: improve counters returned from the upload
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/kopia/kopia/internal/serverapi"
|
|
"github.com/kopia/kopia/internal/uitask"
|
|
)
|
|
|
|
func (s *Server) handleTaskList(ctx context.Context, r *http.Request, body []byte) (interface{}, *apiError) {
|
|
tasks := s.taskmgr.ListTasks()
|
|
if tasks == nil {
|
|
tasks = []uitask.Info{}
|
|
}
|
|
|
|
return serverapi.TaskListResponse{
|
|
Tasks: tasks,
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) handleTaskInfo(ctx context.Context, r *http.Request, body []byte) (interface{}, *apiError) {
|
|
taskID := mux.Vars(r)["taskID"]
|
|
|
|
t, ok := s.taskmgr.GetTask(taskID)
|
|
if !ok {
|
|
return nil, notFoundError("task not found")
|
|
}
|
|
|
|
return t, nil
|
|
}
|
|
|
|
func (s *Server) handleTaskSummary(ctx context.Context, r *http.Request, body []byte) (interface{}, *apiError) {
|
|
return s.taskmgr.TaskSummary(), nil
|
|
}
|
|
|
|
func (s *Server) handleTaskLogs(ctx context.Context, r *http.Request, body []byte) (interface{}, *apiError) {
|
|
taskID := mux.Vars(r)["taskID"]
|
|
|
|
return serverapi.TaskLogResponse{
|
|
Logs: s.taskmgr.TaskLog(taskID),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) handleTaskCancel(ctx context.Context, r *http.Request, body []byte) (interface{}, *apiError) {
|
|
s.taskmgr.CancelTask(mux.Vars(r)["taskID"])
|
|
|
|
return &serverapi.Empty{}, nil
|
|
}
|