Skip to content

Commit

Permalink
feat: Invalidate failed polls
Browse files Browse the repository at this point in the history
  • Loading branch information
dippynark committed Nov 9, 2021
1 parent bc4b229 commit f4ac302
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
Expand Down Expand Up @@ -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")
}
}
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/poller/pollstate/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package pollstate

type Interface interface {
IsNew(repository, operation, values string) (bool, error)
Invalidate(repository, operation, invalidValue string)
}
13 changes: 13 additions & 0 deletions pkg/poller/pollstate/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit f4ac302

Please sign in to comment.