Skip to content

Commit

Permalink
add a --hard-retries option (#30)
Browse files Browse the repository at this point in the history
* feat: add a --hard-retries option

* fix: don't cut off the help message for --retries in the middle of a sentence

* move hard_reties config to OtherConfig

* ci: fix

---------

Co-authored-by: yzqzss <[email protected]>
  • Loading branch information
DigitalDwagon and yzqzss authored Oct 9, 2024
1 parent db2818c commit ffed938
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-dumogenerator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.12", "3.13.0-rc.1"]
python-version: ["3.8", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand All @@ -40,4 +40,4 @@ jobs:
python -m wikiteam3.dumpgenerator -h
- name: Test with pytest
run: |
cd wikiteam3/dumpgenerator && pytest && cd ../../
pytest
2 changes: 1 addition & 1 deletion wikiteam3/dumpgenerator/api/page_titles.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def getPageTitlesAPI(config: Config, session: requests.Session):
delay_session = SessionMonkeyPatch(
session=session, config=config,
add_delay=True, delay_msg="Session delay: "+__name__,
hard_retries=3
hard_retries=3 # TODO: --hard-retries
)
delay_session.hijack()
for namespace in namespaces:
Expand Down
9 changes: 7 additions & 2 deletions wikiteam3/dumpgenerator/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def getArgumentParser():
"if you wanna reuse the connection]"
)
parser.add_argument(
"--retries", metavar="5", default=5, help="Maximum number of retries for "
"--retries", metavar="5", default=5, help="Maximum number of retries for each request before failing."
)
parser.add_argument(
"--hard-retries", metavar="3", default=3, help="Maximum number of hard retries for each request before failing. (for now, this only controls the hard retries during images downloading)"
)
parser.add_argument("--path", help="path to store wiki dump at")
parser.add_argument(
Expand Down Expand Up @@ -290,7 +293,7 @@ def get_parameters(params=None) -> Tuple[Config, OtherConfig]:
# Create session
mod_requests_text(requests) # monkey patch # type: ignore
session = requests.Session()
patch_sess = SessionMonkeyPatch(session=session, hard_retries=1)
patch_sess = SessionMonkeyPatch(session=session, hard_retries=1) # hard retry once to avoid spending too much time on initial detection
patch_sess.hijack()
def print_request(r: requests.Response, *args, **kwargs):
# TODO: use logging
Expand Down Expand Up @@ -548,6 +551,8 @@ def sleep(self, response=None):
assert_max_images = args.assert_max_images,
assert_max_images_bytes = args.assert_max_images_bytes,

hard_retries = int(args.hard_retries),

upload = args.upload,
uploader_args = args.uploader_args,
)
Expand Down
3 changes: 3 additions & 0 deletions wikiteam3/dumpgenerator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,8 @@ class OtherConfig:
assert_max_images: Optional[int]
assert_max_images_bytes: Optional[int]

hard_retries: int
""" Number of hard retries """

upload: bool
uploader_args: List[str]
2 changes: 1 addition & 1 deletion wikiteam3/dumpgenerator/dump/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def modify_headers(headers: Optional[Dict] = None) -> Dict:
return headers


patch_sess = SessionMonkeyPatch(session=session, config=config, hard_retries=3)
patch_sess = SessionMonkeyPatch(session=session, config=config, hard_retries=other.hard_retries)
patch_sess.hijack()

ia_session = requests.Session()
Expand Down

0 comments on commit ffed938

Please sign in to comment.