From f4ac302005e562a16461164c8b354372db7c070f Mon Sep 17 00:00:00 2001 From: Luke Addison Date: Tue, 9 Nov 2021 19:32:58 +0000 Subject: [PATCH] feat: Invalidate failed polls --- pkg/poller/poller.go | 6 +++++- pkg/poller/pollstate/interface.go | 1 + pkg/poller/pollstate/memory.go | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/poller/poller.go b/pkg/poller/poller.go index 667121533..32389dc12 100644 --- a/pkg/poller/poller.go +++ b/pkg/poller/poller.go @@ -74,6 +74,7 @@ func (c *pollingController) PollReleases() { // lets git clone and see if the latest git commit sha is new... owner, repo := scm.Split(fullName) ref := "" + sha := "" fc := filebrowser.NewFetchCache() err := c.fb.WithDir(owner, repo, ref, fc, func(dir string) error { executor, err := git.NewCensoringExecutor(dir, censor, l) @@ -85,7 +86,7 @@ func (c *pollingController) PollReleases() { if err != nil { return errors.Wrapf(err, "failed to get latest git commit sha") } - sha := strings.TrimSpace(string(out)) + sha = strings.TrimSpace(string(out)) if sha == "" { return errors.Errorf("could not find latest git commit sha") } @@ -133,6 +134,7 @@ func (c *pollingController) PollReleases() { return nil }) if err != nil { + c.pollstate.Invalidate(fullName, "release", sha) l.WithError(err).Warn("failed to poll release") } } @@ -175,11 +177,13 @@ func (c *pollingController) PollPullRequests() { }) err = c.pollPullRequest(ctx, l2, fullName, pr, prName, sha) if err != nil { + c.pollstate.Invalidate(fullName, prName, "created") l2.WithError(err).Error("failed to check for PullRequestHook") continue } err = c.pollPullRequestPushHook(ctx, l2, fullName, pr, prName, sha) if err != nil { + c.pollstate.Invalidate(fullName, prName+"-push", sha) l2.WithError(err).Error("failed to check for PullRequestHook") continue } diff --git a/pkg/poller/pollstate/interface.go b/pkg/poller/pollstate/interface.go index 289e9c6e7..d0b41c14d 100644 --- a/pkg/poller/pollstate/interface.go +++ b/pkg/poller/pollstate/interface.go @@ -2,4 +2,5 @@ package pollstate type Interface interface { IsNew(repository, operation, values string) (bool, error) + Invalidate(repository, operation, invalidValue string) } diff --git a/pkg/poller/pollstate/memory.go b/pkg/poller/pollstate/memory.go index ac3baa91d..4e55662bc 100644 --- a/pkg/poller/pollstate/memory.go +++ b/pkg/poller/pollstate/memory.go @@ -25,3 +25,16 @@ func (p *memoryPollstate) IsNew(repository, operation, newValue string) (bool, e p.lock.Unlock() return old != newValue, nil } + +func (p *memoryPollstate) Invalidate(repository, operation, invalidValue string) { + key := repository + ":" + operation + + p.lock.Lock() + + currentValue := p.cache[key] + if currentValue == invalidValue { + delete(p.cache, key) + } + + p.lock.Unlock() +}