Skip to content

Commit

Permalink
Merge pull request #675 from Scalingo/fix/CRON-66/no_cron_task
Browse files Browse the repository at this point in the history
fix(crontasks): display an empty table in case of 404
  • Loading branch information
EtienneM committed Aug 24, 2021
2 parents 1f9baf8 + 4f60b91 commit a947118
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
5 changes: 2 additions & 3 deletions cmd/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (
"strings"
"time"

"github.com/stvp/rollbar"
"gopkg.in/errgo.v1"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
"github.com/Scalingo/go-scalingo/v4"
"github.com/Scalingo/go-scalingo/v4/debug"
httpclient "github.com/Scalingo/go-scalingo/v4/http"
"github.com/Scalingo/go-utils/errors"
"github.com/stvp/rollbar"
"gopkg.in/errgo.v1"
)

type Sysinfo struct {
Expand Down
16 changes: 12 additions & 4 deletions crontasks/list.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package crontasks

import (
"os"

"github.com/Scalingo/cli/config"
httpclient "github.com/Scalingo/go-scalingo/v4/http"
"github.com/Scalingo/go-utils/errors"
"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
"os"
"gopkg.in/errgo.v1"
)

func List(app string) error {
client, err := config.ScalingoClient()
if err != nil {
return errors.Wrap(err, "fail to get Scalingo client")
return errgo.Notef(err, "fail to get Scalingo client")
}

cronTasks, err := client.CronTasksGet(app)
if err != nil {
return errors.Wrap(err, "fail to get cron tasks")
rootError := errors.ErrgoRoot(err)
if !httpclient.IsRequestFailedError(rootError) || rootError.(*httpclient.RequestFailedError).Code != 404 {
return errgo.Notef(err, "fail to get cron tasks")
}

// A 404 only means there is no cron task configured on the application. In this case, we want to display an empty table.
}

t := tablewriter.NewWriter(os.Stdout)
Expand Down
41 changes: 18 additions & 23 deletions deployments/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,29 @@ func List(app string) error {
}
deployments, err := c.DeploymentList(app)
if err != nil {
return errgo.Mask(err)
return errgo.Notef(err, "fail to list the application deployments")
}

if len(deployments) == 0 {
t := tablewriter.NewWriter(os.Stdout)
t.SetHeader([]string{"ID", "Date", "Duration", "User", "Git Ref", "Status"})

} else {
t := tablewriter.NewWriter(os.Stdout)
t.SetHeader([]string{"ID", "Date", "Duration", "User", "Git Ref", "Status"})

for _, deployment := range deployments {
var duration string
if deployment.Duration != 0 {
d, _ := time.ParseDuration(fmt.Sprintf("%ds", deployment.Duration))
duration = d.String()
} else {
duration = "n/a"
}
t.Append([]string{deployment.ID,
deployment.CreatedAt.Format(utils.TimeFormat),
duration,
deployment.User.Username,
deployment.GitRef,
string(deployment.Status),
})
for _, deployment := range deployments {
var duration string
if deployment.Duration != 0 {
d, _ := time.ParseDuration(fmt.Sprintf("%ds", deployment.Duration))
duration = d.String()
} else {
duration = "n/a"
}
t.Render()

t.Append([]string{deployment.ID,
deployment.CreatedAt.Format(utils.TimeFormat),
duration,
deployment.User.Username,
deployment.GitRef,
string(deployment.Status),
})
}
t.Render()

return nil
}

0 comments on commit a947118

Please sign in to comment.