Files
kopia/internal/server/api_tasks.go
Jarek Kowalski 9cba4a97be refactor(repository): major server code refactoring (#1837)
This removes big shared lock held for for the duration of each request
and replaces it with trivially short lock to capture the current
state of the server/repository before passing it to handlers.

Handlers are now limited to only accessing a small subset of Server
functionality to be able to better reason about them.
2022-03-19 22:01:38 -07:00

49 lines
1.1 KiB
Go

package server
import (
"context"
"github.com/kopia/kopia/internal/serverapi"
"github.com/kopia/kopia/internal/uitask"
)
func handleTaskList(ctx context.Context, rc requestContext) (interface{}, *apiError) {
tasks := rc.srv.taskManager().ListTasks()
if tasks == nil {
tasks = []uitask.Info{}
}
return serverapi.TaskListResponse{
Tasks: tasks,
}, nil
}
func handleTaskInfo(ctx context.Context, rc requestContext) (interface{}, *apiError) {
taskID := rc.muxVar("taskID")
t, ok := rc.srv.taskManager().GetTask(taskID)
if !ok {
return nil, notFoundError("task not found")
}
return t, nil
}
func handleTaskSummary(ctx context.Context, rc requestContext) (interface{}, *apiError) {
return rc.srv.taskManager().TaskSummary(), nil
}
func handleTaskLogs(ctx context.Context, rc requestContext) (interface{}, *apiError) {
taskID := rc.muxVar("taskID")
return serverapi.TaskLogResponse{
Logs: rc.srv.taskManager().TaskLog(taskID),
}, nil
}
func handleTaskCancel(ctx context.Context, rc requestContext) (interface{}, *apiError) {
rc.srv.taskManager().CancelTask(rc.muxVar("taskID"))
return &serverapi.Empty{}, nil
}