Complete Tasks implementation
twerthi opened this issue · comments
Is your feature request related to a problem? Please describe.
I was attempting to get a list of queued tasks so I could cancel them. I found the TasksQuery, but client doesn't have a method to pass it to.
Describe the solution you'd like
Use the TasksQuery to query tasks and return the ones matching the query.
Describe alternatives you've considered
Most likey not the best solution, but it does work,
func GetQueuedTasks(octopusURL *url.URL, APIKey string, space *octopusdeploy.Space) []interface{} {
// Query api for tasks
tasksApi := octopusURL.String() + "/api/" + space.ID + "/tasks?States=Queued&Name=Deploy"
// Create http client
httpClient := &http.Client{}
// perform request
request, _ := http.NewRequest("GET", tasksApi, nil)
request.Header.Set("X-Octopus-ApiKey", APIKey)
response, err := httpClient.Do(request)
if err != nil {
log.Println(err)
}
responseData, err := ioutil.ReadAll(response.Body)
var f interface{}
jsonErr := json.Unmarshal(responseData, &f)
if jsonErr != nil {
log.Println(err)
}
tasks := f.(map[string]interface{})
// return the tasks
return tasks["Items"].([]interface{})
}```
**Additional context**
Add any other context or screenshots about the feature request here.
Here's how to perform the same step (as above) with this change:
query := octopusdeploy.TasksQuery{
Name: "Deploy",
States: []string{"Queued"},
}
tasks, err := client.Tasks.Get(query)