Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase timeout for syncing repositories #788

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/controlplane/handlers_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,20 @@ func (s *Server) SyncRepositories(ctx context.Context, in *pb.SyncRepositoriesRe
return nil, status.Errorf(codes.Internal, "cannot create github client: %v", err)
}

tmoutCtx, cancel := context.WithTimeout(ctx, github.ExpensiveRestCallTimeout)
defer cancel()

isOrg := (owner_filter != "")
repos, err := client.ListAllRepositories(ctx, isOrg, owner_filter)
repos, err := client.ListAllRepositories(tmoutCtx, isOrg, owner_filter)
if err != nil {
return nil, status.Errorf(codes.Internal, "cannot list repositories: %v", err)
}

// // Insert the repositories into the database
err = queries.SyncRepositoriesWithDB(ctx, s.store, repos, in.Provider, in.GroupId)
// This uses the context with the extended timeout to allow for the
// database to be populated with the repositories. Otherwise the original context
// expires and the database insertions are cancelled.
err = queries.SyncRepositoriesWithDB(tmoutCtx, s.store, repos, in.Provider, in.GroupId)
if err != nil {
return nil, status.Errorf(codes.Internal, "cannot sync repositories: %v", err)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/providers/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ import (
"context"
"net/http"
"net/url"
"time"

"github.com/google/go-github/v53/github"
"github.com/shurcooL/graphql"
"golang.org/x/oauth2"
)

const (
// ExpensiveRestCallTimeout is the timeout for expensive REST calls
ExpensiveRestCallTimeout = 15 * time.Second
)

// GitHubConfig is the struct that contains the configuration for the GitHub client
// Token: is the GitHub API token retrieved from the provider_access_tokens table
// in the database
Expand Down