-
Notifications
You must be signed in to change notification settings - Fork 95
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
common: general improvements #713
Conversation
Reviewer's Guide by SourceryThis pull request introduces several improvements to the download process, including retries with exponential backoff, enhanced error messages, and the addition of a console module for consistent output formatting. Sequence diagram for improved file download process with retriessequenceDiagram
participant C as Client
participant D as download_file
participant H as HttpClient
participant S as Server
C->>D: download_file(url, dest_path)
activate D
loop max_retries (5 times)
D->>H: init(url, headers, output_file)
activate H
H->>S: HTTP Request
alt Success
S-->>H: File Data
H-->>D: Success
D-->>C: Return
else HTTP 416 (Range Not Satisfiable)
S-->>H: 416 Error
H-->>D: Already downloaded
D-->>C: Return
else Network/Timeout Error
S-->>H: Error/Timeout
H-->>D: Error
D->>D: Wait (exponential backoff)
Note over D: Retry if attempts < 5
end
deactivate H
end
alt Max retries reached
D-->>C: Exit with error message
end
deactivate D
Class diagram for new console moduleclassDiagram
class console {
+bool EMOJI
+bool FORCE_EMOJI
+is_locale_utf8()
+supports_emoji()
+error(msg)
+warning(msg)
+info(msg)
}
note for console "New module for consistent
formatted console output
with emoji support"
Flow diagram for emoji support detectionflowchart TD
A[Check emoji support] --> B{RAMALAMA_FORCE_EMOJI set?}
B -->|Yes| C{Value is 'true'?}
C -->|Yes| D[Enable emoji]
C -->|No| E[Disable emoji]
B -->|No| F{Check TERM env}
F -->|dumb/linux| E
F -->|other| G{Check UTF-8 locale}
G -->|Yes| D
G -->|No| E
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
9f86dec
to
e80d41d
Compare
I believe the code is ready for review this time. Please let me know if I missed something. |
e80d41d
to
018bd6f
Compare
- if timeout happens we try 5 times before sending Timeout error to users. - improve user experience when timeout occurs - Added console source tree for handling messages Resolves: containers#693 Signed-off-by: Douglas Schilling Landgraf <[email protected]>
018bd6f
to
b0678aa
Compare
import logging | ||
|
||
|
||
def is_locale_utf8(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this on macOS with alacritty it needs one more check to work, because this is the only env var (LC_ALL) of the 3 env vars populated on this platform:
$ echo $LC_ALL
en_IE.UTF-8
So we need to add one more or:
return 'UTF-8' in os.getenv('LC_CTYPE', '') or 'UTF-8' in os.getenv('LANG', '') or 'UTF-8' in os.getenv('LC_ALL', '')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also do:
return any('UTF-8' in os.getenv(var, '') for var in ['LC_CTYPE', 'LANG', 'LC_ALL'])
to be less long-winded, as long as it works I don't mind too much. And it just checks these three env vars for UTF-8, I don't care after that point.
# If RAMALAMA_FORCE_EMOJI is not set, it defaults to checking supports_emoji() | ||
RAMALAMA_FORCE_EMOJI = os.getenv("RAMALAMA_FORCE_EMOJI") | ||
FORCE_EMOJI = RAMALAMA_FORCE_EMOJI.lower() == "true" if RAMALAMA_FORCE_EMOJI else None | ||
EMOJI = FORCE_EMOJI if FORCE_EMOJI is not None else supports_emoji() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 21-23 are long-winded it took me a while to read this and try and understand if it was correct, lets simplify:
EMOJI = os.getenv("RAMALAMA_FORCE_EMOJI") or supports_emoji()
Make lint is a good one to have. Signed-off-by: Douglas Schilling Landgraf <[email protected]>
This PR is much easier to review, a much more focused PR. I think we are close. |
|
||
|
||
# Define emoji-aware logging messages | ||
def error(msg): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spacing isn't consistent in the printed output in these three functions, some are double-space some are single-space.
If you are pushing new commits you might as well catch it here, we can also do in a follow on PR.
I'll catch the changes in another PR I have the time |
if timeout happens we try 5 times before sending Timeout error to users.
improve user experience when timeout occurs
Added console source tree for handling messages
Resolves: #693
Summary by Sourcery
Improve the reliability of file downloads and introduce logging with user-friendly messages.
Bug Fixes:
Enhancements: