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

Feature | Add methods to dynamically set/unset retry options #454

Draft
wants to merge 3 commits into
base: v3
Choose a base branch
from

Conversation

viicslen
Copy link

@viicslen viicslen commented Sep 4, 2024

This PR adds methods in the HasTries trait to allow the retry options to be set dynamically (mainly when using resources)

$this->connector
	->withRetry(tries: 3, intervalMilliseconds: 1000, exponentialBackoff: true, , throwOnMaxTries: true)
	->admin()
	->externalProducts()
	->upsertExternalProduct($productId, $data);


$this->connector
	->withRetry(3)
	->withRetryInterval(1000)
	->withExponentialBackoff()
	->throwOnMaxTries()
	->admin()
	->externalProducts()
	->upsertExternalProduct($productId, $data)

This will also allow to unset these options for specific requests

$this->connector
	->withoutRetry()
	->admin()
	->externalProducts()
	->upsertExternalProduct($productId, $data);


$this->connector
	->withRetry(3)
	->withRetryInterval(null)
	->withExponentialBackoff(false)
	->throwOnMaxTries(false)
	->admin()
	->externalProducts()
	->upsertExternalProduct($productId, $data)

$this->connector
	->withRetry(3)
	->withoutRetryInterval()
	->withoutExponentialBackoff()
	->throwOnMaxTries(false)
	->admin()
	->externalProducts()
	->upsertExternalProduct($productId, $data)

This is just a draft PR, it would still be missing tests and method comments to follow the other methods in the trait, I will happily add them if you thing this would be a good addition

To Do:

  • Tests
  • Method docblocks

@Sammyjo20
Copy link
Member

I've wanted this myself for quite a while, so yes @viicslen I'd love this! Thank you for the suggestion, if you could add tests etc let me know and I'll review it :)

@Sammyjo20 Sammyjo20 changed the title Add methods to dynamically set/unset retry options Feature | Add methods to dynamically set/unset retry options Dec 3, 2024
@juse-less
Copy link
Contributor

I find the without*() methods-, and the withRetry() method a bit problematic, for the lack of a better word.

The withRetry() method accepts nullable values, but only checks for truey values.
So passing false as argument for the boolean parameters will be ignored.
Same thing if 0 is passed as interval; although this might be undesirable anyway.

The without*() methods are a bit inconsistent, in that the integer-based ones sets null.
Whereas the boolean-based ones sets false, even though their values are also nullable.
Without digging too deep into how the retry feature works, the boolean values are not always considered false when the value is null.
Although, I guess it makes sense semantically that non-boolean values are set to null, and boolean values are set to false with without*() methods.

But I think it would at least make sense to check if values are not null in withRetry(), so that values that are false are still being set.
And maybe withoutRetry() should explicitly set the values to false.

It's also possible I'm just overthinking this.

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.

3 participants