@@ -29,11 +29,11 @@ type service struct {
type pkgIssues struct {
Open, Closed []issues.Issue
}
func newService() *service {
func newService(ctx context.Context) *service {
packageIssues := emptyPackages()
// Initialize list of packages sorted by import path, standard library first.
var packages []string
for p := range packageIssues {
@@ -51,11 +51,11 @@ func newService() *service {
s := &service{
PackageIssues: packageIssues,
Packages: packages,
}
go s.poll()
go s.poll(ctx)
return s
}
func emptyPackages() map[string]*pkgIssues {
// Initialize places for issues, using existing packages
@@ -93,43 +93,41 @@ func isStandard(p string) bool {
p = p[:i]
}
return !strings.Contains(p, ".")
}
func (s *service) poll() {
corpus, repo, err := initCorpus()
func (s *service) poll(ctx context.Context) {
corpus, repo, err := initCorpus(ctx)
if err != nil {
log.Fatalln("poll: initial initCorpus failed:", err)
}
for {
packageIssues := packageIssues(repo)
s.PackageIssuesMu.Lock()
s.PackageIssues = packageIssues
s.PackageIssuesMu.Unlock()
for {
started := time.Now()
updateError := corpus.Update(context.Background())
updateError := corpus.Update(ctx)
if updateError == maintner.ErrSplit {
log.Println("corpus.Update: Corpus out of sync. Re-fetching corpus.")
corpus, repo, err = initCorpus()
corpus, repo, err = initCorpus(ctx)
if err != nil {
log.Fatalln("poll: post-ErrSplit initCorpus failed:", err)
}
} else if updateError != nil {
log.Printf("corpus.Update: %v; sleeping 15s", updateError)
time.Sleep(15 * time.Second)
continue
}
log.Printf("got corpus update after %v", time.Since(started))
break
}
}
}
func initCorpus() (*maintner.Corpus, *maintner.GitHubRepo, error) {
corpus, err := godata.Get(context.Background())
func initCorpus(ctx context.Context) (*maintner.Corpus, *maintner.GitHubRepo, error) {
corpus, err := godata.Get(ctx)
if err != nil {
return nil, nil, fmt.Errorf("godata.Get: %v", err)
}
repo := corpus.GitHub().Repo("golang", "go")
if repo == nil {