Skip to content

Commit

Permalink
Merge pull request #82 from justinclayton/add_list_tasks_route
Browse files Browse the repository at this point in the history
add route to list all running tasks
  • Loading branch information
alde committed May 16, 2016
2 parents 0048902 + d1ad73c commit bba2073
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions database/task.go
Expand Up @@ -86,6 +86,7 @@ func ListNonTerminalTasks() ([]*types.EremeticTask, error) {
var task types.EremeticTask
json.Unmarshal(v, &task)
if !task.IsTerminated() {
applyMask(&task)
tasks = append(tasks, &task)
}
return nil
Expand All @@ -95,3 +96,9 @@ func ListNonTerminalTasks() ([]*types.EremeticTask, error) {

return tasks, err
}

func applyMask(task *types.EremeticTask) {
for k := range task.MaskedEnvironment {
task.MaskedEnvironment[k] = "*******"
}
}
12 changes: 12 additions & 0 deletions handler/handler.go
Expand Up @@ -96,6 +96,18 @@ func GetTaskInfo(scheduler types.Scheduler) http.HandlerFunc {
}
}

// ListRunningTasks returns information about running tasks in the database.
func ListRunningTasks(scheduler types.Scheduler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
logrus.Debug("Fetching all tasks")
tasks, err := database.ListNonTerminalTasks()
if err != nil {
handleError(err, w, "Unable to fetch running tasks from the database")
}
writeJSON(200, tasks, w)
}
}

func handleError(err error, w http.ResponseWriter, message string) {
if err == nil {
return
Expand Down
17 changes: 17 additions & 0 deletions misc/swagger.yaml
Expand Up @@ -10,6 +10,19 @@ produces:
- application/json
paths:
/task:
get:
summary: List running tasks
description: |
List all running tasks, masking values in MaskedEnvironment.
responses:
200:
description: Task details
schema:
$ref: '#/definitions/Task'
404:
description: No tasks found
default:
description: Unexpected error
post:
summary: Launch a task
consumes:
Expand Down Expand Up @@ -60,6 +73,10 @@ definitions:
host_path:
type: string
description: Path on host to mount
Tasks:
type: array
items:
$ref: '#/definitions/Task'
Task:
type: object
required:
Expand Down
6 changes: 6 additions & 0 deletions routes/routes.go
Expand Up @@ -30,6 +30,12 @@ func Create(scheduler types.Scheduler) *mux.Router {
Pattern: "/task/{taskId}",
Handler: handler.GetTaskInfo(scheduler),
},
types.Route{
Name: "ListRunningTasks",
Method: "GET",
Pattern: "/task",
Handler: handler.ListRunningTasks(scheduler),
},
}

router := mux.NewRouter().StrictSlash(true)
Expand Down

0 comments on commit bba2073

Please sign in to comment.