Skip to content

Commit

Permalink
Add GetTaskStatusesWithLimit(limit)
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Aug 26, 2015
1 parent 12c1185 commit 835b677
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 51 deletions.
19 changes: 19 additions & 0 deletions api/director_task_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cloudfoundry-community/gogobosh/net"
)

// GetTaskStatuses returns a list of most recent task statuses
func (repo BoshDirectorRepository) GetTaskStatuses() (tasks []models.TaskStatus, apiResponse net.ApiResponse) {
taskResponses := []taskStatusResponse{}

Expand All @@ -23,6 +24,24 @@ func (repo BoshDirectorRepository) GetTaskStatuses() (tasks []models.TaskStatus,
return
}

// GetTaskStatusesWithLimit returns a max of 'limit' task statuses
func (repo BoshDirectorRepository) GetTaskStatusesWithLimit(limit int) (tasks []models.TaskStatus, apiResponse net.ApiResponse) {
taskResponses := []taskStatusResponse{}

path := fmt.Sprintf("/tasks?limit=%d", limit)
apiResponse = repo.gateway.GetResource(repo.config.TargetURL+path, repo.config.Username, repo.config.Password, &taskResponses)
if apiResponse.IsNotSuccessful() {
return
}

for _, resource := range taskResponses {
tasks = append(tasks, resource.ToModel())
}

return
}

// GetTaskStatus returns details of a specific task to allow polling for state change
func (repo BoshDirectorRepository) GetTaskStatus(taskID int) (task models.TaskStatus, apiResponse net.ApiResponse) {
taskResponse := taskStatusResponse{}

Expand Down
10 changes: 9 additions & 1 deletion example/bosh-lite-example.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ func main() {
fmt.Println("")
}

task, apiResponse := repo.GetTaskStatus(1)
tasks, apiResponse := repo.GetTaskStatusesWithLimit(3)
if apiResponse.IsNotSuccessful() {
fmt.Println("Could not fetch tasks")
return
} else {
fmt.Printf("%#v\n", tasks)
}

task, apiResponse := repo.GetTaskStatus(tasks[0].ID)
if apiResponse.IsNotSuccessful() {
fmt.Println("Could not fetch BOSH task 1")
return
Expand Down
50 changes: 0 additions & 50 deletions example/current_target.go

This file was deleted.

0 comments on commit 835b677

Please sign in to comment.