Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Dec 5, 2024
1 parent 41e2d5d commit 634c957
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
10 changes: 5 additions & 5 deletions cmd/deployments/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ func showLogsFollow(
ce *clienv.CliEnv,
cl *nhostclient.Client,
deploymentID string,
) error {
) (string, error) {
ticker := time.NewTicker(time.Second * 2) //nolint:mnd

printed := make(map[string]struct{})

for {
select {
case <-ctx.Done():
return nil
return "", nil
case <-ticker.C:
resp, err := cl.GetDeploymentLogs(ctx, deploymentID)
if err != nil {
return fmt.Errorf("failed to get deployments: %w", err)
return "", fmt.Errorf("failed to get deployments: %w", err)
}

for _, log := range resp.GetDeploymentLogs() {
Expand All @@ -95,7 +95,7 @@ func showLogsFollow(
}

if resp.Deployment.DeploymentEndedAt != nil {
return nil
return *resp.Deployment.DeploymentStatus, nil
}
}
}
Expand All @@ -118,7 +118,7 @@ func commandLogs(cCtx *cli.Context) error {
ctx, cancel := context.WithTimeout(cCtx.Context, cCtx.Duration(flagTimeout))
defer cancel()

if err := showLogsFollow(ctx, ce, cl, deploymentID); err != nil {
if _, err := showLogsFollow(ctx, ce, cl, deploymentID); err != nil {
return err
}
} else {
Expand Down
11 changes: 9 additions & 2 deletions cmd/deployments/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func CommandNew() *cli.Command {
[]cli.Flag{
&cli.BoolFlag{ //nolint:exhaustruct
Name: flagFollow,
Usage: "Specify if the logs should be streamed",
Usage: "Specify if the logs should be streamed. If set, the command will wait for the deployment to finish and stream the logs. If the deployment fails the command will return an error.", //nolint:lll
Value: false,
},
&cli.DurationFlag{ //nolint:exhaustruct
Expand Down Expand Up @@ -103,7 +103,14 @@ func commandNew(cCtx *cli.Context) error {
ctx, cancel := context.WithTimeout(cCtx.Context, cCtx.Duration(flagTimeout))
defer cancel()

return showLogsFollow(ctx, ce, cl, resp.InsertDeployment.ID)
status, err := showLogsFollow(ctx, ce, cl, resp.InsertDeployment.ID)
if err != nil {
return fmt.Errorf("error streaming logs: %w", err)
}

if status != "DEPLOYED" {
return fmt.Errorf("deployment failed: %s", status) //nolint:goerr113
}
}

return nil
Expand Down
8 changes: 8 additions & 0 deletions nhostclient/graphql/client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nhostclient/graphql/query/deployments.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ query GetDeploymentLogs($deploymentID: uuid!) {
id: $deploymentID
) {
deploymentEndedAt
deploymentStatus
}
}

Expand Down

0 comments on commit 634c957

Please sign in to comment.