当前位置: 首页>>代码示例>>Golang>>正文


Golang ECS.ListTasks方法代码示例

本文整理汇总了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
}
开发者ID:masonoise,项目名称:ecsman,代码行数:20,代码来源:tasks.go

示例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
}
开发者ID:CpuID,项目名称:ecs-discoverer,代码行数:47,代码来源:shared.go

示例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
}
开发者ID:colinmutter,项目名称:go-ecs,代码行数:46,代码来源:ecs.go

示例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)
}
开发者ID:gawkermedia,项目名称:ecs,代码行数:4,代码来源:task.go


注:本文中的github.com/aws/aws-sdk-go/service/ecs.ECS.ListTasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。