Http resilience and fixes - #3
Open
msgrDiablo wants to merge 4 commits into
Open
Conversation
Cockpit content is fetched over HTTP on every request, so a brief backend unavailability (e.g. an nginx/Cockpit container being recreated during a deploy) used to surface directly as "cURL error 7: Failed to connect" and an error page for the visitor. - Retry middleware: retries connection-level failures (ConnectException) and transient 5xx responses with exponential backoff (250/500/1000 ms); 4xx responses are never retried. - Default timeouts: connect_timeout 2 s, total timeout 30 s (0 disables the limit). The total timeout is deliberately generous: an exceeded timeout surfaces as cURL error 28 / ConnectException and is retried too, so a tight default would multiply the load caused by slow batch reads (console commands fetching whole collections) and still fail. - New setHttpOptions() to tune retries and timeouts per project. - The client is built once and cached instead of being recreated on every request; the unused base_uri was dropped (requests always pass absolute URLs).
…ror handling - getAssetPath() used ltrim() with the uploads dir as its second argument, which treats it as a character set, not a prefix: paths like /storage/uploads/documents/x.pdf were mangled to cuments/x.pdf whenever the first path segment started with one of the characters of "/storage/uploads". Strip the prefix with str_starts_with() + substr() instead, and normalize the sizes branch the same way. - getEntry() now passes limit 1 instead of fetching the whole collection just to return its first entry. - get() decodes responses with JSON_THROW_ON_ERROR, so an invalid response fails with a clear JsonException instead of a null dereference on the next line.
- Extract initialization (onLoadEntry callbacks + wrapping nested arrays in Entry objects) into init() and trigger it from getIterator(), count() and offsetExists() too. Previously foreach/count/isset bypassed it, so iteration yielded raw arrays and skipped the callbacks (e.g. localization) unless some field had been read first. - offsetGet() returns null for a missing key instead of emitting an "undefined array key" warning. - toArray() recursively unwraps nested Entry objects, so it returns the raw underlying array even after initialization. - offsetSet() throws InvalidArgumentException instead of a generic Exception.
- Write the README (it previously contained only the repo name): installation, Nette DI configuration, collections/singletons/Entry usage, assets, HTTP resilience defaults and tuning guidance (tight timeout for latency-sensitive pages, raised or disabled timeout for console commands and batch reads of large collections), callbacks and error handling. - License the package as MIT: LICENSE file, composer.json license field and README section. - Add a composer.json description.
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.
řeší to 3 věci:
je to komplementární se všemi projekty kde to používáme, zpětně kompatibilni
tag na posledním commitu pushnu teda až po ev. mergnutí jo?