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

refactor: replace goto with for #85

Merged
merged 6 commits into from Apr 7, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions publisher/lock/s3_lock.go
Expand Up @@ -90,15 +90,14 @@ func NewS3(c S3Config, logfn Logf) (*S3, error) {

// Lock S3 has no compare-and-swap so this is no bulletproof solution, but should be good enough.
func (l *S3) Lock() error {
var tries uint
retry:
if (l.conf.MaxRetries - tries) > 0 {
tries++
for tries := 0; tries < int(l.conf.MaxRetries); tries++ {
l.logF("%s attempt %d", l.conf.Owner, tries)
if l.isBusyDeletingExpired() {
if tries >= int(l.conf.MaxRetries) {
break
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this could be removed , the for condition prevents this case

l.logF("%s failed, waiting %s", l.conf.Owner, l.conf.RetryBackoff.String())
time.Sleep(l.conf.RetryBackoff)
goto retry
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something to escape the loop is needed if not busy , could be a else+break or something similar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean? the for condition will exit the loop

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if if l.isBusyDeletingExpired() { is not true i think it should exit the loop and continue with the execution as it was doing with the goto logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true! otherwise in case of long busy it will wait an extra time in the end before exiting

varas marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down