Repository navigation
fix: retry link previews after temporary failures - #160
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
UpdateLinkPreviewsetfetched_atwhenever a fetch threw, including connection errors, timeouts, and unexpected errors, and it treated 5xx responses like any other unsuccessful response.UnfurlLinkskips previews that already havefetched_at, so a short outage on the linked site lost the card permanently.Behavior now
Permanent outcomes are still marked as fetched with no metadata and never retried:
Transient outcomes are retried by the queued job with backoff: connection errors, timeouts with no partial body, 5xx, 429, and unexpected errors.
UnfurlLinknow has 3 tries with a 1-minute and then a 10-minute backoff. If the last attempt also fails,failed()marks the preview as fetched with no metadata, so it isn't retried again.Implementation
UpdateLinkPreview::handle()no longer catches anything. On a 5xx or 429 it calls$response->throw(). AConnectionExceptionwas already rethrown byget(), and a body that arrived before a timeout cut it off is still used. Anything else that throws goes to the queue as-is.UnfurlLinknow uses#[Tries(3)]and#[Backoff([60, 600])], the same pattern asSyncGitHubSshKeysJob, and has afailed()hook. No scheduler is needed.Validation
tests/Unit/Actions/UpdateLinkPreviewTest.php,tests/Unit/Jobs/UnfurlLinkTest.php,tests/Unit/ArchTest.php,tests/Unit/Actions/CreateCommitTest.php,tests/Unit/Models/LinkPreviewTest.php(116 tests).databasequeue worker (queue:work --once) with time travel. They check that a retry doesn't run before the backoff ends, that a later success stores the metadata, and that the preview is marked fetched only after the third failure.pint,rector --dry-runandphpstanpass on the touched scope. Type coverage is 100%.--coverage --exactly=100.0is the check. Every new branch has a test.Media
No screenshots or videos: nothing in the UI changes. This only changes when the background job retries a fetch and when it gives up. A link card looks the same as before; it's just no longer lost after a temporary outage.
Limitations
failed_jobs. This matchesSyncGitHubSshKeysJob. Before, they were swallowed silently.