feat(cronjobs): add shared HTTP client wrapper. Refs #1214#1253
feat(cronjobs): add shared HTTP client wrapper. Refs #1214#1253Prasad8830 wants to merge 5 commits into
Conversation
regulartim
left a comment
There was a problem hiding this comment.
Hey @Prasad8830 ! Nice work overall! :) A few things though:
- The issue was also about standardized logging but I can see no logging here. Please add a sensible amount of logging and also be thoughtful with the log levels.
- The retry behavior is not actually tested. Please add some tests for that, especially for the POST + retry case.
Thank you for bringing that to my attention! I will make the necessary corrections. |
| total=retries, | ||
| status_forcelist=[429, 500, 502, 503, 504], | ||
| backoff_factor=backoff_factor, | ||
| allowed_methods=frozenset(["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE", "POST"]), |
There was a problem hiding this comment.
I just noticed that this might be a problem: retrying POST/PUT/DELETE requests can lead to unexpected behaviour on non-idempotent calls. For example posting the same malware data twice. POST is also not in the defaults. What do you think about that?
There was a problem hiding this comment.
Can you please answer this question?
|
Hey @Prasad8830 ! Are you still working on this? |
Yes, I was working on this migration, and along with this PR, I created two more PRs. Since this project was part of GSoC 2026, is it still open for contributions? |
Yes, I saw that. But this has to get merged first, the other two are based on the changes here, right?
Of course! We are always open to contributions! :) |
|
BTW, the CI is failing because of a new Ruff linting rule that we recently introduced. In |
Ok, then I will fix current PRs, and then I will do the migration of the next APIs. |
Hi @regulartim, I have fix this bug. |
|
Hey @Prasad8830 ! Unfortunately the linter is still not happy. Make merge the |
Hi @regulartim, can you now check? I merged develop and fixed the failing tests |
regulartim
left a comment
There was a problem hiding this comment.
Hey @Prasad8830 ! Linter is happy now! 👍 But you did not address the feedback from my last review, as far as I can see.
| total=retries, | ||
| status_forcelist=[429, 500, 502, 503, 504], | ||
| backoff_factor=backoff_factor, | ||
| allowed_methods=frozenset(["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE", "POST"]), |
There was a problem hiding this comment.
Can you please answer this question?
Description
This PR introduces a shared HTTP client wrapper (
HttpClient) based onrequests.Sessionfor our cronjob fetchers. This represents the first step towards standardising how cron jobs handle timeouts, retries, and errors, as discussed in #1214.The wrapper automatically applies a default 10-second timeout, implements an exponential backoff retry strategy for standard server errors/rate limits, and consistently enforces
raise_for_status(). Full unit tests for this wrapper have been included.Note: This PR only introduces the wrapper and its tests. Subsequent PRs will migrate
tor_exit_nodes,whatsmyip, and the remaining endpoints to use this new client.Related issues
Type of change
Checklist
Formalities
<feature name>. Closes #999develop.develop.Docs and tests
Ruff) gave 0 errors. If you have correctly installed pre-commit, it runs these checks and makes these adjustments on your behalf.GUI changes
Ignore this section if you did not make any changes to the GUI.