github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/task.go (about)

     1  package ccv3
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     5  	"code.cloudfoundry.org/cli/resources"
     6  )
     7  
     8  // CreateApplication resources.Task runs a command in the Application environment
     9  // associated with the provided Application GUID.
    10  func (client *Client) CreateApplicationTask(appGUID string, task resources.Task) (resources.Task, Warnings, error) {
    11  	var responseBody resources.Task
    12  
    13  	_, warnings, err := client.MakeRequest(RequestParams{
    14  		RequestName:  internal.PostApplicationTasksRequest,
    15  		URIParams:    internal.Params{"app_guid": appGUID},
    16  		RequestBody:  task,
    17  		ResponseBody: &responseBody,
    18  	})
    19  
    20  	return responseBody, warnings, err
    21  }
    22  
    23  // GetApplicationTasks returns a list of tasks associated with the provided
    24  // application GUID. Results can be filtered by providing URL queries.
    25  func (client *Client) GetApplicationTasks(appGUID string, query ...Query) ([]resources.Task, Warnings, error) {
    26  	var tasks []resources.Task
    27  
    28  	_, warnings, err := client.MakeListRequest(RequestParams{
    29  		RequestName:  internal.GetApplicationTasksRequest,
    30  		URIParams:    internal.Params{"app_guid": appGUID},
    31  		Query:        query,
    32  		ResponseBody: resources.Task{},
    33  		AppendToList: func(item interface{}) error {
    34  			tasks = append(tasks, item.(resources.Task))
    35  			return nil
    36  		},
    37  	})
    38  
    39  	return tasks, warnings, err
    40  }
    41  
    42  // UpdateTaskCancel cancels a task.
    43  func (client *Client) UpdateTaskCancel(taskGUID string) (resources.Task, Warnings, error) {
    44  	var responseBody resources.Task
    45  
    46  	_, warnings, err := client.MakeRequest(RequestParams{
    47  		RequestName: internal.PutTaskCancelRequest,
    48  		URIParams: internal.Params{
    49  			"task_guid": taskGUID,
    50  		},
    51  		ResponseBody: &responseBody,
    52  	})
    53  
    54  	return responseBody, warnings, err
    55  }
    56  
    57  func (client *Client) GetTask(guid string) (resources.Task, Warnings, error) {
    58  	var responseBody resources.Task
    59  
    60  	_, warnings, err := client.MakeRequest(RequestParams{
    61  		RequestName: internal.GetTaskRequest,
    62  		URIParams: internal.Params{
    63  			"task_guid": guid,
    64  		},
    65  		ResponseBody: &responseBody,
    66  	})
    67  
    68  	return responseBody, warnings, err
    69  }