Skip to content

Commit f1567a1

Browse files
Use bounded fetch operation names across manager wait paths
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 3b56695 commit f1567a1

10 files changed

Lines changed: 29 additions & 11 deletions

File tree

hyperbrowser/client/managers/async_manager/crawl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from hyperbrowser.models.consts import POLLING_ATTEMPTS
44
from ...polling import (
5+
build_fetch_operation_name,
56
collect_paginated_results_async,
67
poll_until_terminal_status_async,
78
retry_operation_async,
@@ -67,7 +68,7 @@ async def start_and_wait(
6768

6869
if not return_all_pages:
6970
return await retry_operation_async(
70-
operation_name=f"Fetching crawl job {job_id}",
71+
operation_name=build_fetch_operation_name(f"crawl job {job_id}"),
7172
operation=lambda: self.get(job_id),
7273
max_attempts=POLLING_ATTEMPTS,
7374
retry_delay_seconds=0.5,

hyperbrowser/client/managers/async_manager/scrape.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from hyperbrowser.models.consts import POLLING_ATTEMPTS
44
from ...polling import (
5+
build_fetch_operation_name,
56
collect_paginated_results_async,
67
poll_until_terminal_status_async,
78
retry_operation_async,
@@ -74,7 +75,7 @@ async def start_and_wait(
7475

7576
if not return_all_pages:
7677
return await retry_operation_async(
77-
operation_name=f"Fetching batch scrape job {job_id}",
78+
operation_name=build_fetch_operation_name(f"batch scrape job {job_id}"),
7879
operation=lambda: self.get(job_id),
7980
max_attempts=POLLING_ATTEMPTS,
8081
retry_delay_seconds=0.5,

hyperbrowser/client/managers/async_manager/web/batch_fetch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
)
1111
from hyperbrowser.exceptions import HyperbrowserError
1212
from ....polling import (
13+
build_fetch_operation_name,
1314
collect_paginated_results_async,
1415
poll_until_terminal_status_async,
1516
retry_operation_async,
@@ -75,7 +76,7 @@ async def start_and_wait(
7576

7677
if not return_all_pages:
7778
return await retry_operation_async(
78-
operation_name=f"Fetching batch fetch job {job_id}",
79+
operation_name=build_fetch_operation_name(f"batch fetch job {job_id}"),
7980
operation=lambda: self.get(job_id),
8081
max_attempts=POLLING_ATTEMPTS,
8182
retry_delay_seconds=0.5,

hyperbrowser/client/managers/async_manager/web/crawl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
)
1111
from hyperbrowser.exceptions import HyperbrowserError
1212
from ....polling import (
13+
build_fetch_operation_name,
1314
collect_paginated_results_async,
1415
poll_until_terminal_status_async,
1516
retry_operation_async,
@@ -73,7 +74,7 @@ async def start_and_wait(
7374

7475
if not return_all_pages:
7576
return await retry_operation_async(
76-
operation_name=f"Fetching web crawl job {job_id}",
77+
operation_name=build_fetch_operation_name(f"web crawl job {job_id}"),
7778
operation=lambda: self.get(job_id),
7879
max_attempts=POLLING_ATTEMPTS,
7980
retry_delay_seconds=0.5,

hyperbrowser/client/managers/sync_manager/crawl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from hyperbrowser.models.consts import POLLING_ATTEMPTS
44
from ...polling import (
5+
build_fetch_operation_name,
56
collect_paginated_results,
67
poll_until_terminal_status,
78
retry_operation,
@@ -67,7 +68,7 @@ def start_and_wait(
6768

6869
if not return_all_pages:
6970
return retry_operation(
70-
operation_name=f"Fetching crawl job {job_id}",
71+
operation_name=build_fetch_operation_name(f"crawl job {job_id}"),
7172
operation=lambda: self.get(job_id),
7273
max_attempts=POLLING_ATTEMPTS,
7374
retry_delay_seconds=0.5,

hyperbrowser/client/managers/sync_manager/scrape.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from hyperbrowser.models.consts import POLLING_ATTEMPTS
44
from ...polling import (
5+
build_fetch_operation_name,
56
collect_paginated_results,
67
poll_until_terminal_status,
78
retry_operation,
@@ -72,7 +73,7 @@ def start_and_wait(
7273

7374
if not return_all_pages:
7475
return retry_operation(
75-
operation_name=f"Fetching batch scrape job {job_id}",
76+
operation_name=build_fetch_operation_name(f"batch scrape job {job_id}"),
7677
operation=lambda: self.get(job_id),
7778
max_attempts=POLLING_ATTEMPTS,
7879
retry_delay_seconds=0.5,

hyperbrowser/client/managers/sync_manager/web/batch_fetch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
)
1111
from hyperbrowser.exceptions import HyperbrowserError
1212
from ....polling import (
13+
build_fetch_operation_name,
1314
collect_paginated_results,
1415
poll_until_terminal_status,
1516
retry_operation,
@@ -73,7 +74,7 @@ def start_and_wait(
7374

7475
if not return_all_pages:
7576
return retry_operation(
76-
operation_name=f"Fetching batch fetch job {job_id}",
77+
operation_name=build_fetch_operation_name(f"batch fetch job {job_id}"),
7778
operation=lambda: self.get(job_id),
7879
max_attempts=POLLING_ATTEMPTS,
7980
retry_delay_seconds=0.5,

hyperbrowser/client/managers/sync_manager/web/crawl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
)
1111
from hyperbrowser.exceptions import HyperbrowserError
1212
from ....polling import (
13+
build_fetch_operation_name,
1314
collect_paginated_results,
1415
poll_until_terminal_status,
1516
retry_operation,
@@ -73,7 +74,7 @@ def start_and_wait(
7374

7475
if not return_all_pages:
7576
return retry_operation(
76-
operation_name=f"Fetching web crawl job {job_id}",
77+
operation_name=build_fetch_operation_name(f"web crawl job {job_id}"),
7778
operation=lambda: self.get(job_id),
7879
max_attempts=POLLING_ATTEMPTS,
7980
retry_delay_seconds=0.5,

hyperbrowser/client/polling.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _validate_operation_name(operation_name: str) -> None:
6666
raise HyperbrowserError("operation_name must not contain control characters")
6767

6868

69-
def _build_fetch_operation_name(operation_name: str) -> str:
69+
def build_fetch_operation_name(operation_name: str) -> str:
7070
prefixed_operation_name = f"{_FETCH_OPERATION_NAME_PREFIX}{operation_name}"
7171
if len(prefixed_operation_name) <= _MAX_OPERATION_NAME_LENGTH:
7272
return prefixed_operation_name
@@ -800,7 +800,7 @@ def wait_for_job_result(
800800
max_wait_seconds=max_wait_seconds,
801801
max_status_failures=max_status_failures,
802802
)
803-
fetch_operation_name = _build_fetch_operation_name(operation_name)
803+
fetch_operation_name = build_fetch_operation_name(operation_name)
804804
return retry_operation(
805805
operation_name=fetch_operation_name,
806806
operation=fetch_result,
@@ -837,7 +837,7 @@ async def wait_for_job_result_async(
837837
max_wait_seconds=max_wait_seconds,
838838
max_status_failures=max_status_failures,
839839
)
840-
fetch_operation_name = _build_fetch_operation_name(operation_name)
840+
fetch_operation_name = build_fetch_operation_name(operation_name)
841841
return await retry_operation_async(
842842
operation_name=fetch_operation_name,
843843
operation=fetch_result,

tests/test_polling.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import hyperbrowser.client.polling as polling_helpers
1313
from hyperbrowser.client.polling import (
14+
build_fetch_operation_name,
1415
collect_paginated_results,
1516
collect_paginated_results_async,
1617
poll_until_terminal_status,
@@ -41,6 +42,15 @@ def test_poll_until_terminal_status_returns_terminal_value():
4142
assert status == "completed"
4243

4344

45+
def test_build_fetch_operation_name_prefixes_when_within_length_limit():
46+
assert build_fetch_operation_name("crawl job 123") == "Fetching crawl job 123"
47+
48+
49+
def test_build_fetch_operation_name_falls_back_for_max_length_inputs():
50+
operation_name = "x" * 200
51+
assert build_fetch_operation_name(operation_name) == operation_name
52+
53+
4454
def test_poll_until_terminal_status_allows_immediate_terminal_on_zero_max_wait():
4555
status = poll_until_terminal_status(
4656
operation_name="sync immediate zero wait",

0 commit comments

Comments
 (0)