Skip to content

Commit

Permalink
Merge pull request #2 from swartzrock/pagination-fix
Browse files Browse the repository at this point in the history
Pagination fix
  • Loading branch information
swartzrock authored Dec 15, 2020
2 parents cab7687 + 9e687bd commit 067d744
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions cmd/aws/awsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func DescribeClusters() ([]*ecs.Cluster, error) {
include := "STATISTICS"

err := client.ListClustersPagesWithContext(context.Background(), &ecs.ListClustersInput{}, func(output *ecs.ListClustersOutput, b bool) bool {
if len(output.ClusterArns) == 0 {
return false
}
clusterDetails, err := client.DescribeClusters(&ecs.DescribeClustersInput{
Clusters: output.ClusterArns,
Include: []*string{&include},
Expand Down Expand Up @@ -58,6 +61,9 @@ func DescribeClusterServices(c *ecs.Cluster) ([]*ecs.Service, error) {
var services []*ecs.Service

err := client.ListServicesPagesWithContext(context.Background(), &ecs.ListServicesInput{Cluster: c.ClusterArn}, func(output *ecs.ListServicesOutput, b bool) bool {
if len(output.ServiceArns) == 0 {
return false
}
serviceDetails, err := client.DescribeServices(&ecs.DescribeServicesInput{
Cluster: c.ClusterArn,
Services: output.ServiceArns,
Expand Down Expand Up @@ -87,6 +93,9 @@ func DescribeClusterTasks(c *ecs.Cluster) ([]*ecs.Task, error) {
var tasks []*ecs.Task

err := client.ListTasksPagesWithContext(context.Background(), &ecs.ListTasksInput{Cluster: c.ClusterArn}, func(output *ecs.ListTasksOutput, b bool) bool {
if len(output.TaskArns) == 0 {
return false
}
taskDetails, err := client.DescribeTasks(&ecs.DescribeTasksInput{
Cluster: c.ClusterArn,
Tasks: output.TaskArns,
Expand Down Expand Up @@ -142,6 +151,9 @@ func DescribeContainerInstances(c *ecs.Cluster) ([]*ecs.ContainerInstance, error
var containerInstances []*ecs.ContainerInstance

err := client.ListContainerInstancesPagesWithContext(context.Background(), &ecs.ListContainerInstancesInput{Cluster: c.ClusterArn}, func(output *ecs.ListContainerInstancesOutput, b bool) bool {
if len(output.ContainerInstanceArns) == 0 {
return false
}
containerDetails, err := client.DescribeContainerInstances(&ecs.DescribeContainerInstancesInput{
Cluster: c.ClusterArn,
ContainerInstances: output.ContainerInstanceArns,
Expand Down
9 changes: 6 additions & 3 deletions cmd/utils/stringutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ func BuildAsciiMeterCurrentTotal(portion int64, total int64, width int) string {
const fullChar = "█"
const emptyChar = "▒"

ratio := float64(portion) / float64(total)
ratio = math.Max(0, math.Min(1.0, ratio))
full := int(math.Round(ratio * float64(width)))
full := 0
if total > 0 {
ratio := float64(portion) / float64(total)
ratio = math.Max(0, math.Min(1.0, ratio))
full = int(math.Round(ratio * float64(width)))
}

return strings.Join([]string{
strings.Repeat(fullChar, full),
Expand Down

0 comments on commit 067d744

Please sign in to comment.