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: retry logic for deployment key #223

Merged

Conversation

mohitsethia
Copy link
Contributor

@mohitsethia mohitsethia commented Jul 16, 2024

Closes #152

Sometimes, a build might be triggered before the repository is registered, which mean a deployment key was added. For these reason we have a retry logic here https://github.com/taubyte/tau/services/monkey/job.go#L88. Frankly, this code does not look good.

I suggest moving the check for deployment key to https://github.com/taubyte/tau/services/monkey/job.go#L41, and use a helper function that will retry for a number of times till we get repo with a deployment key.

Add a reusable Retry helper function.

@@ -39,3 +43,79 @@ func (m *Monkey) storeLogs(r io.ReadSeeker) (string, error) {

return cid, nil
}

// Retry function with a custom condition
func Retry(maxRetries int, waitBeforeRetry time.Duration, operation interface{}, condition interface{}, args ...interface{}) ([]interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

tests are passing. however, i'm no sure using interface{} (should be any btw) is a good choice here.
make a retry just for our use case since it's used only once.

Copy link
Contributor Author

@mohitsethia mohitsethia Jul 17, 2024

Choose a reason for hiding this comment

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

Thanks for your comment. I have reverted and moved the retry logic to helpers.
I just needed one advise on how to get the global variable for maxRetries and waitBeforeRetry?

@samyfodil samyfodil marked this pull request as ready for review July 18, 2024 05:48
@samyfodil samyfodil merged commit 2224d3f into taubyte:main Jul 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor retry logic for deployment key
2 participants