本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/ecs.ECS.ListTasks方法的典型用法代码示例。如果您正苦于以下问题:Golang ECS.ListTasks方法的具体用法?Golang ECS.ListTasks怎么用?Golang ECS.ListTasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/aws/aws-sdk-go/service/ecs.ECS
的用法示例。
在下文中一共展示了ECS.ListTasks方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getServiceTasks
//
// Given a service, fetches the tasks associated with it and returns them in an array.
//
func getServiceTasks(awsConn *ecs.ECS, clusterName string, serviceName string) []*ecs.Task {
taskOutput, err := awsConn.ListTasks(&ecs.ListTasksInput{
Cluster: &clusterName,
ServiceName: &serviceName,
})
CheckError("fetching task list for service", err)
var serviceTasks []*ecs.Task
if len(taskOutput.TaskArns) > 0 {
taskInfo, err := awsConn.DescribeTasks(&ecs.DescribeTasksInput{
Tasks: taskOutput.TaskArns,
Cluster: &clusterName,
})
CheckError("fetching task data for service", err)
serviceTasks = taskInfo.Tasks
}
return serviceTasks
}
示例2: GetContainerInstanceArnsForService
func GetContainerInstanceArnsForService(ecs_obj *ecs.ECS, cluster string, service string, local_container_instance_arn string, debug bool) ([]string, error) {
// Fetch a task list based on the service name.
list_tasks_params := &ecs.ListTasksInput{
Cluster: &cluster,
ServiceName: &service,
}
list_tasks_resp, list_tasks_err := ecs_obj.ListTasks(list_tasks_params)
if list_tasks_err != nil {
return []string{}, fmt.Errorf("Cannot retrieve ECS task list: %s", FormatAwsError(list_tasks_err))
}
if len(list_tasks_resp.TaskArns) <= 0 {
return []string{}, fmt.Errorf("No ECS tasks found with specified filter - cluster: ", cluster, ", service:", service)
}
// Describe the tasks retrieved above.
describe_tasks_params := &ecs.DescribeTasksInput{
Cluster: &cluster,
Tasks: list_tasks_resp.TaskArns,
}
describe_tasks_resp, describe_tasks_err := ecs_obj.DescribeTasks(describe_tasks_params)
if describe_tasks_err != nil {
return []string{}, fmt.Errorf("Cannot retrieve ECS task details:", FormatAwsError(describe_tasks_err))
}
if len(describe_tasks_resp.Tasks) <= 0 {
return []string{}, fmt.Errorf("No ECS task details found with specified filter - tasks:", strings.Join(aws.StringValueSlice(list_tasks_resp.TaskArns), ", "))
}
var result []string
for _, value := range describe_tasks_resp.Tasks {
if *value.LastStatus == "RUNNING" && *value.ContainerInstanceArn != local_container_instance_arn {
result = append(result, *value.ContainerInstanceArn)
} else {
if debug == true {
fmt.Println(*value.ContainerInstanceArn, "is not in a RUNNING state, or is this instance (we dont return ourself). Excluded from results.")
}
}
}
if len(result) == 0 {
return []string{}, fmt.Errorf("No ECS task results found in RUNNING state, no ECS container instances to return.")
}
return result, nil
}
示例3: GetTasks
// GetTasks will return a slice of ECS Tasks within a cluster
func GetTasks(svc *ecs.ECS, cluster *string) ([]*ecs.Task, error) {
var taskArns []*string
// List clusters
reqParams := &ecs.ListTasksInput{
Cluster: cluster,
MaxResults: aws.Int64(100),
NextToken: aws.String(""),
}
// Loop through tokens until no more results remain
for {
resp, err := svc.ListTasks(reqParams)
// Error check
if err != nil {
return nil, fmt.Errorf("ecs.ListTasks: %s", err.Error())
}
// Expand slice of tasks and append to our comprehensive list
taskArns = append(taskArns, resp.TaskArns...)
// Cycle token
if resp.NextToken != nil {
reqParams.NextToken = resp.NextToken
} else {
// Kill loop ... out of response pages
break
}
}
// Describe the tasks that we just got back
resp, err := svc.DescribeTasks(&ecs.DescribeTasksInput{
Cluster: cluster,
Tasks: taskArns,
})
if err != nil {
return nil, fmt.Errorf("ecs.DescribeTasks: %s", err.Error())
}
return resp.Tasks, nil
}
示例4: ListTasks
// ListTasks Returns a list of tasks for a specified cluster.
func ListTasks(svc *ecs.ECS, params *ecs.ListTasksInput) (*ecs.ListTasksOutput, error) {
return svc.ListTasks(params)
}